Disclaimer: I'm sure this has been answered before but I cannot find anything on SO or Google.
So, I have a CMS that essentially consists of a Page, Region, Widget format. A single Page can have unlimited Regions, and a Region can have unlimited Widgets.
Right now my schema looks like this:
Table: pages
Columns: id, title, uri, ...
Table: regions
Columns: id, page_id, name, title
Table: widget_types
Columns: id, title, active
Table: widget_assignments
Columns: id, region_id, widget_type_id, data
(data represents content/settings for a specific instance of a Widget)
This works great for simple widgets. What I want to do is let every Widget Type have it's own table(s). For example, a simple content widget would have a table like this:
Table: wt_content
Columns: id, content
An example of a more complex widget (eg forums) might look something like this:
Table: wt_forums
Columns: id, ...
Table: wt_forum_threads
Columns: id, ...
Table: wt_forum_categories
Columns: id, ...
Table: wt_forum_settings
Columns: id, ...
The only way I know how to make this happen is to add a table
column and a reference_id
to the widget_assignments
table, like this:
Table: widget_assignments
Columns: id, region_id, widget_type_id, table, reference_id
The thing I hate about this is I'll have to do a bunch of queries each page load. I'll have to:
- SELECT all widget assignments and regions for the current page (that's one query with joins)
- Then loop through each widget assignment and do a look up for the actual widget.
That is potentially a crap load of queries! There has to be a better way. I'm open to anything at this point.
Thanks.