Setting up a self-referential many-to-many relationship

2007-03-06 Thread thelorax

Hello,

I just started playing with Cake yesterday and am trying to set up a
self referential many to many relationship using an example of users/
friends that is common to most social networks.  To set up the DB I
created two tables; users with id and username, and friends with
user_id and friend_id (both keys that reference users.id).  As of now,
I am just playing in scaffolding and have defined my user model as
follows:


 array('className' 
=> 'User',
 
'joinTable' => 'friends',
 
'foreignKey' => 'user_id',
 
'associationForeignKey' => 'friend_id',
'conditions' => '', 

 'order' =>
'', 
 
'limit' => '',
'unique' => 'true', 

 'finderQuery' =>
'', 
 'deleteQuery' => ''
  )
);
}

?>

Let's say I add a row in my friends table in which user_id = 1 and
friend_id = 2.  With this I am able to see a user 1's related friends
in my scaffolding.  However, when I view user 2's entry, I only see
User 1 appear as a friend if I have created another row in my friends
table in which user_id = user 2 and friend_id = user 1.   I guess I
could add two records as described above, each time people become
friends, but it seems like it would be more efficient to in create one
record and have the relationship go in both directions.  The only
problem is that I don't know how to set  this up in cake.  Any ideas?

thanks.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Setting up a self-referential many-to-many relationship

2007-03-06 Thread thelorax

Hello,

I just started playing with Cake yesterday and am trying to set up a
self referential many to many relationship using an example of users/
friends that is common to most social networks.  To set up the DB I
created two tables; users with id and username, and friends with
user_id and friend_id (both keys that reference users.id).  As of now,
I am playing in scaffolding and have defined my user model as follows:


 array('className' 
=> 'User',
 
'joinTable' => 'users_friends',
 
'foreignKey' => 'user_id',
 
'associationForeignKey' =>
'friend_id',
'conditions' =>
'', 

'order' => '',  

'limit' =>
'', 

'unique' =>
'true', 

'finderQuery' =>
'', 

'deleteQuery' => ''

),


);
}

?>


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---