Friday, January 2, 2009

Re: Selecting users who are not friends

First, you should reall be using find('all') not findAll, as in:

$friends = $this->User-find('all', array('conditions' => array
('User.id' => $target)));

To find all the users who are not friends, simply use the following:

$notFriends = $this->User-find('all', array('conditions' => array
('NOT' => array('User.id' => $target))));

On Dec 29 2008, 12:59 pm, WebFeathers <webfeath...@gmail.com> wrote:
> Hey-
> I'm trying to generate a list of users who are not friends of the
> currently logged in user.
> I have two tables: profiles, and users_users
> profiles includes the fields: id, first_name, last_name, etc...
> users_users includes: id, user_id, friend_id
>
> I can get the list of users who ARE friends:
> $friends = $this->User->findAll('User.id=' . $target);
>
> ...but can't figure out how to go the other way???
>
> My user model includes:
> class User extends AppModel
> {
>         var $name = 'User';
>         var $hasAndBelongsToMany = array(
>                 'Friends' => array(
>                         'className' => 'Profile',
>                         'joinTable' =>'users_users',
>                         'foreignKey' =>'user_id',
>                         'associationForeignKey' => 'friend_id',
>                         'unique'=> true
>                         ),
>                 'FriendList' => array(
>                         'className' => 'users_users',
>                         'joinTable' =>'users_users',
>                         'foreignKey' =>'user_id',
>                         'associationForeignKey' => 'friend_id',
>                         'unique'=> true
>                         )
>         );
>
> }
>
>
--~--~---------~--~----~------------~-------~--~----~
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: