Hey All,

I'm working on a project wherein I would like to implement a model that 
hasAndBelongsToMany of itself. To better illustrate this, imagine a data 
structure composed of linking nodes not unlike that of a tree. Instead of 
one parent and many child nodes, however, my structure has many parent nodes 
and many child nodes. The sequence of the nodes is still important (i.e. I 
still require a separation of children and parents). I would like to retain 
the ability to transverse the structure by traveling to any parent or any 
child from the node at which I currently sit, and so I believe HABTM 
relationships to be the answer.

My attempt to solve this conundrum was to implement a node table and two 
join tables - children and parents - both of which taking the place of what 
would be conventionally named nodes_nodes tables. The "children" join table 
consists of two columns - 'node_id' and 'child_id' - as does the "parents" 
join table - 'node_id' and 'parent_id'.
 
And so my Node model holds the HABTM associations

'Child' => array(
'className' => 'Node',
'joinTable' => 'children',
'foreignKey' => 'node_id',
'associationForeignKey' => 'child_id'

) ,

'Parent' => array( 

'className' => 'Node',

'joinTable' => 'parents', 

'foreignKey' => 'node_id', 

'associationForeignKey' => 'parent_id'

)


This approach has got me far as the Bake utility generating controllers and 
views that provide the option to select multiple Nodes as parents and 
children while adding or updating, however the selected parent/children are 
not actually inserted into the join tables.

And so I ask: am I going about this in the right manner? If not, or if you 
have an alternate suggestion - I'm all ears! Please point me in the correct 
direction :)

Thank you very much for your time and consideration,
~KuroTstuo

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to