Welcome Guest, Not a member yet? Register   Sign In
Menu Model
#7

[eluser]jedd[/eluser]
[quote author="Think Floyd" date="1236884865"]
DB structure:

TABLE: category

id
title

TABLE : subcategory
id
title

JOIN TABLE: categories_subcategories
category_id
subcategory_id
[/quote]

May I suggest that life would be simpler, and this is true IFF you are sticking with two levels here, to have two tables instead. Roughly like:
Code:
CREATE TABLE category
     id          SERIAL,
     title       VARCHAR

CREATE TABLE subcategory
      id         SERIAL
      cat_id     BIGINT    // FK to category.id of course
      title      VARCHAR

Your current schema only allows two levels deep anyway because of the limitations of the 'join' table.

If you wanted to get excited you could have a single table that had a parent ID column (0 denotes category, etc). This is pretty standard stuff, though.

Point being, your selects would be easier, and consequently your code would be easier (read: your problem would be easier).


Messages In This Thread
Menu Model - by El Forum - 03-12-2009, 07:00 AM
Menu Model - by El Forum - 03-12-2009, 07:29 AM
Menu Model - by El Forum - 03-12-2009, 07:42 AM
Menu Model - by El Forum - 03-12-2009, 07:48 AM
Menu Model - by El Forum - 03-12-2009, 08:01 AM
Menu Model - by El Forum - 03-12-2009, 08:07 AM
Menu Model - by El Forum - 03-12-2009, 08:35 AM
Menu Model - by El Forum - 03-12-2009, 08:40 AM
Menu Model - by El Forum - 03-12-2009, 08:48 AM
Menu Model - by El Forum - 03-12-2009, 08:49 AM
Menu Model - by El Forum - 03-12-2009, 09:34 AM
Menu Model - by El Forum - 03-12-2009, 09:51 AM
Menu Model - by El Forum - 03-12-2009, 10:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB