Hi,

Thanks for replying to my thread :)

I've tried the following habtm relationship.  I get an interesting
result.  As I'm sure you'll see in the array below the 'children'
array doesn't have anything but the children are showing up just not
in the right 'children' array for some reason.  Any ideas?

Array
(
    [0] => Array
        (
            [Content] => Array
                (
                    [name] => Home
                    [id] => 1
                    [link] => /
                    [parent_id] =>
                    [0] => Array
                        (
                            [id] => 2
                            [name] => Operations
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 1
                            [parent_id] =>
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [name] => Leadership
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 2
                            [parent_id] =>
                        )

                    [2] => Array
                        (
                            [id] => 4
                            [name] => Culture and Mission
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 3
                            [parent_id] =>
                        )

                    [3] => Array
                        (
                            [id] => 5
                            [name] => Product Knowledge and Quality
Standards
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 4
                            [parent_id] =>
                        )

                    [4] => Array
                        (
                            [id] => 6
                            [name] => Links
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 5
                            [parent_id] =>
                        )

                    [5] => Array
                        (
                            [id] => 7
                            [name] => About the U
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 6
                            [parent_id] =>
                        )

                    [6] => Array
                        (
                            [id] => 8
                            [name] => En Espanol
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 7
                            [parent_id] =>
                        )

                    [7] => Array
                        (
                            [id] => 9
                            [name] => Contact
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 8
                            [parent_id] =>
                        )

                    [8] => Array
                        (
                            [id] => 10
                            [name] => Search
                            [description] =>
                            [link] =>
                            [level] => 0
                            [order] => 9
                            [parent_id] =>
                        )

                    [9] => Array
                        (
                            [id] => 11
                            [name] => Site Map
                            [description] =>
                            [link] => /contents/site_map/
                            [level] => 0
                            [order] => 10
                            [parent_id] =>
                        )

                )

            [children] => Array
                (
                )

        )

    [1] => Array
        (
            [Content] => Array
                (
                    [name] => Operations
                    [id] => 2
                    [link] =>
                    [parent_id] =>
                    [0] => Array
                        (
                            [id] => 12
                            [name] => Gainsharing
                            [description] =>
                            [link] =>
                            [level] => 1
                            [order] => 1
                            [parent_id] =>
                        )

                )

            [children] => Array
                (
                )

        )

    [2] => Array
        (
            [Content] => Array
                (
                    [name] => Gainsharing
                    [id] => 12
                    [link] =>
                    [parent_id] =>
                )

            [children] => Array
                (
                )

        )

    [3] => Array
        (
            [Content] => Array
                (
                    [name] => Leadership
                    [id] => 3
                    [link] =>
                    [parent_id] =>
                    [0] => Array
                        (
                            [id] => 12
                            [name] => Gainsharing
                            [description] =>
                            [link] =>
                            [level] => 1
                            [order] => 1
                            [parent_id] =>
                        )

                )

            [children] => Array
                (
                )

        )

    [4] => Array
        (
            [Content] => Array
                (
                    [name] => Culture and Mission
                    [id] => 4
                    [link] =>
                    [parent_id] =>
                    [0] => Array
                        (
                            [id] => 12
                            [name] => Gainsharing
                            [description] =>
                            [link] =>
                            [level] => 1
                            [order] => 1
                            [parent_id] =>
                        )

                )

            [children] => Array
                (
                )

        )

    [5] => Array
        (
            [Content] => Array
                (
                    [name] => Product Knowledge and Quality Standards
                    [id] => 5
                    [link] =>
                    [parent_id] =>
                    [0] => Array
                        (
                            [id] => 12
                            [name] => Gainsharing
                            [description] =>
                            [link] =>
                            [level] => 1
                            [order] => 1
                            [parent_id] =>
                        )

                )

            [children] => Array
                (
                )

        )

    [6] => Array
        (
            [Content] => Array
                (
                    [name] => Links
                    [id] => 6
                    [link] =>
                    [parent_id] =>
                )

            [children] => Array
                (
                )

        )

    [7] => Array
        (
            [Content] => Array
                (
                    [name] => About the U
                    [id] => 7
                    [link] =>
                    [parent_id] =>
                )

            [children] => Array
                (
                )

        )

    [8] => Array
        (
            [Content] => Array
                (
                    [name] => En Espanol
                    [id] => 8
                    [link] =>
                    [parent_id] =>
                )

            [children] => Array
                (
                )

        )

    [9] => Array
        (
            [Content] => Array
                (
                    [name] => Contact
                    [id] => 9
                    [link] =>
                    [parent_id] =>
                )

            [children] => Array
                (
                )

        )

    [10] => Array
        (
            [Content] => Array
                (
                    [name] => Search
                    [id] => 10
                    [link] =>
                    [parent_id] =>
                )

            [children] => Array
                (
                )

        )

    [11] => Array
        (
            [Content] => Array
                (
                    [name] => Site Map
                    [id] => 11
                    [link] => /contents/site_map/
                    [parent_id] =>
                )

            [children] => Array
                (
                )

        )

)

So far I have the following model code:

class Content extends AppModel {

        var $name = 'Content';
        var $useDbConfig = 'WFMU2';
        var $useTable = 'content';

        var $hasAndBelongsToMany = array ('Content' =>
                                                                        
array('className' => 'Content',
                                                                                
'joinTable' => 'contents_contents',
                                                                                
'foreignKey'=> 'content_id',
                                                                                
'associationForeignKey' => 'child_id',
                                                                                
'conditions' => '',
                                                                                
'order'=> '',
                                                                                
'limit'=> '',
                                                                                
'unique'=> true,
                                                                                
'finderQuery'=> '',
                                                                                
'deleteQuery'=> '',
                                                                                
)
                                                                        );
}

Database Tables:

CREATE TABLE `content` (
  `id` bigint(20) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `description` text,
  `link` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;

CREATE TABLE `contents_contents` (
  `content_id` int(11) NOT NULL,
  `child_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


On Jul 12, 1:55 am, AD7six <[EMAIL PROTECTED]> wrote:
> On Jul 11, 5:17 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi all... I'm still pretty new to cakephp and I'm liking it a whole
> > bunch!  However, I was wondering what the model representation would
> > be for a relationship of tables below.
>
> > Basically, I have a navigatation system that is in a tree view.
> > However, I want to set it up where leaf nodes can have many different
> > parents.
>
> > Table 1
> > =======
> > id
> > name
> > link
>
> > Join Table
> > =======
> > id
> > table 1 id
> > table 1 parent id
>
> > I'm not quite sure how to set this up or if this is even correct or
> > heading in the right direction.  Anyone have any advice?
>
> Hi Paul,
>
> Having a tree that allows for each node to have more than one parent
> is likely to be a bit tricky/messy and making it a habtm relationship
> will probably confuse rather than help IMO. I guess/hope you are
> already aware of that.
>
> I think you will find that it is easier to implement if you consider
> the following:
> A node does not have a parent*
> A position (choose whatever name you like for this model) belongsTo
> (Parent,Node)
> A position is a completely normal tree (i.e. it has a parent_id field)
>
> The only 'complexity' then is to ensure that each position points at a
> node. I'd recommend investigating the tree behavior btw.
>
> hth,
>
> AD
> *If you want to know if/where it is referenced as a hasMany Position.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to