Re: Selecting users who are not friends

2009-01-02 Thread Arthur Pemberton

On Fri, Jan 2, 2009 at 10:53 PM, Webweave  wrote:
>
> 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;


That won't grab users who have no friends.


-- 
Fedora 9 : sulphur is good for the skin
( www.pembo13.com )

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Selecting users who are not friends

2009-01-02 Thread Webweave

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  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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Selecting users who are not friends

2008-12-29 Thread WebFeathers

Understood.

So, then I'll keep looking.

...but (in the off-chance that is usable by anyone), I got what I
needed by following your suggestion. Here's what I did:

//Get the Current User's ID (from the session)
  $target = $this->Session->read('User.id');

//Get IDs of all Friends of current user (as a list)
  $myFriends = $this->User->FriendList->find('list', array
('fields'=>'friend_id','conditions' => array('user_id' => $target)));
//Now, add current user's ID to the myFriends array() (don't want to
add myself)
  $myFriends[] = $target;
//This gets me everyone but me and my friends
  $NotFriendsYet = $this->User->findAll(array('NOT' => array('id' =>
$myFriends)));


If there's a simpler solutions, please let me know - but for now I
think this works.

Thanks!
~R~

On Dec 29, 3:22 pm, "Arthur Pemberton"  wrote:
> On Mon, Dec 29, 2008 at 4:21 PM, WebFeathers  wrote:
>
> > Thank you Arthur - I figured I'd have to do it that way - was just
> > looking for a more elegant solution.
>
> > Thanks!
> > ~R~
>
> Keep in mind that I have only been using CakePHP for about a month
> now, someone else may have a more elegant solution. If so, I haven't
> seen it in the book however.
>
> --
> Fedora 9 : sulphur is good for the skin
> (www.pembo13.com)
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Selecting users who are not friends

2008-12-29 Thread Arthur Pemberton

On Mon, Dec 29, 2008 at 4:21 PM, WebFeathers  wrote:
>
> Thank you Arthur - I figured I'd have to do it that way - was just
> looking for a more elegant solution.
>
> Thanks!
> ~R~

Keep in mind that I have only been using CakePHP for about a month
now, someone else may have a more elegant solution. If so, I haven't
seen it in the book however.

-- 
Fedora 9 : sulphur is good for the skin
( www.pembo13.com )

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Selecting users who are not friends

2008-12-29 Thread WebFeathers

Thank you Arthur - I figured I'd have to do it that way - was just
looking for a more elegant solution.

Thanks!
~R~

On Dec 29, 1:54 pm, "Arthur Pemberton"  wrote:
> On Mon, Dec 29, 2008 at 2:59 PM, WebFeathers  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
> >                        )
> >        );
> > }
>
> I believe if you did this in raw SQL, you would need to do a sub
> query. I don't think CakePHPs ORM generates sub queries (subject to
> correction).
>
> The simplest solution would be to generate a list of the ids of the
> friends, and get all users whose id is not in that list.
>
> [1] show how to do an IN condition
>
> [1]http://book.cakephp.org/view/74/Complex-Find-Conditions
>
> --
> Fedora 9 : sulphur is good for the skin
> (www.pembo13.com)
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Selecting users who are not friends

2008-12-29 Thread Arthur Pemberton

On Mon, Dec 29, 2008 at 2:59 PM, WebFeathers  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
>)
>);
> }


I believe if you did this in raw SQL, you would need to do a sub
query. I don't think CakePHPs ORM generates sub queries (subject to
correction).

The simplest solution would be to generate a list of the ids of the
friends, and get all users whose id is not in that list.

[1] show how to do an IN condition

[1] http://book.cakephp.org/view/74/Complex-Find-Conditions

-- 
Fedora 9 : sulphur is good for the skin
( www.pembo13.com )

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Selecting users who are not friends

2008-12-29 Thread WebFeathers

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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---