I need a system that associate users from one single table making them friends. Until now, everything goes fine. The problem is when the user 1 is friend of user 2, cake don't understand that user 2 is friend of user 1 too.
Is there a way to tell Cake to make a "reverse" query? Or I need to insert two records in the table (user_id = 1, friend_id = 2 and user_id = 2, friend_id = 1)?
I'll try to explain better:
I created tables: USERS and USERS_FRIENDS.
USERS fields:
- id, name
USERS_FRIENDS fields:
- id, user_id, friend_id
user.php Model:
var $hasAndBelongsToMany = array(
'Friend' => array(
'className' => 'User',
'joinTable' => 'users_friends',
'foreignKey' => 'user_id',
'associationForeignKey' => 'friend_id',
'with' => 'UsersFriend',
'unique' => false
)
);
users_friend.php Model:
var $belongsTo = array(
'Friend' => array(
'className' => 'Friend',
'joinTable' => 'users',
'foreignKey' => 'friend_id',
),
'User' => array(
'className' => 'User',
'joinTable' => 'users',
'foreignKey' => 'user_id',
)
);
Sorry my english.
Thanks for help!
Att,
Henrique Machado
TI Expert
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment