Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
User Journal

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.

This discussion was created by blinder (153117) for no Foes, but now has been archived. No new comments can be posted.

[Programming] Child and Sibling Data

Comments Filter:
  • all i know is that if we're treating them like MY siblings, you want to get them into quarantine RIGHT NOW, and keep them away from any flammable objects.
  • Only my customer is wanting to do all sorts of crazy stuff with XML. Got a parentID and an ID for each node, trying to make an xsl that will recursively nest nodes. Yay me.
  • Note that I am not in any way a professional. I'd love to hear why these ideas are stupid, and wouldn't work, as a learning experience. But I like to think about this stuff, so...

    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
  • We do much more complex hierarchical stuff in our database, so I have had plenty of experience coming up with solutions to the various problems posed by such a data structure. Our relationships in the database are self-describing which can make for some hairy situations...

    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
    • I know I learned about trees and stuff in my Pascal classes back in 1990 or so. Bad thing is, I only remember we did some recursion and drew some trees, but nothing more. Do you have some recommended (online) reading on trees? Storing them in a DB probably then is quite easy to do once you've done your homework and decided on a strategy and schema. (Or so I assume. I may be naive here. *g*)

      Any feedback is greatly appreciated. :) I want to build a web-based family tree thingamabob for my people as a hobby pr
  • Be a responsible data-owner and have your data neutered before it reproduces.
    • I went to the data pound yesterday and ALMOST adopted these cute little bits. The problem was there were 8 of them, so I was afraid they might byte. Thank you! I'll be here all wee... no I won't! Tomorrow is thanksgiving, and you can be thankful I'm not at your house telling jokes. :-)

To do nothing is to be nothing.

Working...