Friday, July 2, 2010

Re: User HABTM User/Firend (Social Network )

Yeah just package it into a component so that doing the association
both ways isn't a big deal

On Jul 2, 12:02 pm, hugom <ham1...@gmail.com> wrote:
> I insert 2 records, uid_1 and uid_2. It's probably a good way to do
> it. It's just an extra step when you do an insert and an extra step
> when you do a delete.
>
> On Jul 2, 1:51 pm, Henrique Machado <henri....@gmail.com> wrote:
>
> > 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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate