Journal blinder's Journal: [Programming] Child and Sibling Data 7
heh, sam, this may be something you want to think about, this is a real-world problem i am having to solve... well, i think i have a solution, but i want to run it through the je machine to see if someone else has any ideas.
here's the problem in a nut shell. we've got two (database) tables:
- Pages
- PageElements
they basically have this kind of structure:
Pages
============
id int
title varchar
author varchar
keywords varchar
/*... bla other meta-data-like fields */
PageElements
=============
id int
pageid int (fk)
name varchar
value varchar
type varchar
parentid int
so, the concept is that we store pages in the system, and that we'll have N number of page "types" (different combinations of elements like headlines, body copy - we don't want to couple ourselves to a specific set of fields, which is why we have PageElements).
the problem is that we may have pages that have nested elements. for example, lets say a page has a "tab box" a div container that has little navigable tabs at the top, which are controlled by content managers. they can create tabs, and then add items to that particular tab for display.
well, the front end needs to know how to render the display, and therefor needs to know the relationship of the various elements. that being the case, we have two types of data relationships.
those with have clear parent/child such as the following data structure:
PAGE
Headline
Photo
Caption
Tab-Features
Feature-Tab-1
Headline
article_ref
Feature-Tab-2
Headline
article_ref
Special-Message-1
Special-Message-2
Special-Message-3
so, as you can see... there is a parent/child relationship with the tabs, which is being handled by the 'parentid' column on the 'PageElements' table, and our data objects accomodate nesting (which gets messy because we have to examine the data type and determin if we need to "reach further in").
as convoluted as the code will get to handle that, its actually an easy problem. the tougher one is that of siblings ('Special-Message-x') in the above example page structure.
the problem is that we need to create that kind of relationship in the database so that the front end knows it needs to iterate through a 'Special-Message' object, and that means when we collect all of the page's elements, to treat those as siblings, not as individual elements.
i do have an idea of how this may work, but i don't want let the cat out of the bag quite yet in that i'm not completely satisfied that i like it (no, i'm not thinking of storing xml in the database, ugh), meaning, i'm open to other suggestions. i'm the architect on this project so its pretty much up to me to nail this down and anything i say goes on this.
siblings (Score:2)
Working on the same problem... (Score:2)
Two ideas... (Score:2)
1st idea: Since you are implementing parent relationships anyway, I think the quick fix is to create a dummy parent that conatins all the siblings. The advantage is that it uses code you are already building, and isn't an exception. Of course, some people cringe at dummy objects. And depending on how strict your typing is, dum
This is my bread and butter... (Score:1)
You have a number of issues to bear in mind with such a strategy: data complexity, data schema complexity, database code complexity and client code complexity. To make some of the code easier/simpler, you may want to consider various cachi
Re: (Score:2)
Any feedback is greatly appreciated.
Next time... (Score:2)
Re: (Score:2)