A little more information.

I've tried the following:
$this->set('friends', $this->User->Friends->findall('user1_id='.$this-
>User->id));
SQL Error: 1054: Unknown column 'user1_id' in 'where clause'

$this->set('friends', $this->User->Friends-
>findall('Friends.user1_id='.$this->User->id));
SQL Error: 1109: Unknown table 'Friends' in where clause

$this->set('friends', $this->User->Friends-
>findall('users_users.user1_id='.$this->User->id));
SQL Error: 1109: Unknown table 'users_users' in where clause
(the table does exist)

There is no 'Friends' model - it's just the User model attached to
itself through a HABTM relationship (described in my last post).
The 'models' chapter of the manual only describes how to query this
sort of relationship using recursion.  I'm trying to get it to find
the user's friends directly, but I can't figure out how to get it to
understand that it needs to look in the join table for the
relationship.

Am I missing something obvious?  Do I need to clarify what I'm trying
to do?

Thanks again,
Chris


On Jan 19, 1:34 pm, Chris Wade <[EMAIL PROTECTED]> wrote:
> Ah, Chaining was the word I was looking for, but I was thinking that
> it would give you only the records from the chained models that were
> related to the model of the controller you were in.  Thanks for the
> info.
>
> So, to do something like what I want to do, I would have to say 
> $this->User->Friends->findall([set conditions to find the friends related to
>
> the user]).
>
> The 'Friends' relationship is a HABTM relating one user directly to
> another through a table called users_users, which has the fields
> 'user1_id' and 'user2_id'.
>
> In the user model:
>     var $hasAndBelongsToMany = array('Friends' =>
>                                      array('className'             =>
> 'User',
>                                            'joinTable'             =>
> 'users_users',
>                                            'foreignKey'            =>
> 'user1_id',
>                                            'associationForeignKey' =>
> 'user2_id',
>                                            'conditions'            =>
> '',
>                                            'order'                 =>
> 'created DESC',
>                                            'limit'                 =>
> '5',
>                                            'unique'                =>
> true,
>                                            'finderQuery'           =>
> '',
>                                            'deleteQuery'           =>
> ''
>                                      )
>
>     var $hasOne = array('Profile' =>
>                         array('className'  => 'Profile',
>                               'conditions' => '',
>                               'order'      => '',
>                               'dependent'  => true,
>                               'foreignKey' => 'user_id'
>                         ),
>
> Avatars for each user are contained in the user's profile.  Given this
> relationship, how would you go about writing a query that would grab
> the avatars from the profiles for each of the current user's friends,
> without picking up all of the other relationships (there are several
> not mentioned here)?
>
> Thanks for the help.
>
> Chris
>
> On Jan 19, 9:32 am, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
>
> > Chaining isn't bad, but it only gives you a reference for the model,
> > it doesn't set any conditions. You have to pass them manually to the
> > findAll().
>
> > You can unbind() the models you don't want to get on the findAll and
> > set the recursion level that fits your needs. Also it is possible to
> > set conditions dinamically on the associations through
> > Model::bindModel();
>
> > Also if you are using CakePHP 1.2 you can use the bindable behavior
> > (thanks Mariano) to control your associations.
>
> > HTH,
> > - Dardo Sordi.
>
> > On Jan 18, 2008 10:54 PM, the_woodsman <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > I'm not sure I fully understand your problem, but:
>
> > > > I'd like to figure out how to do something like:
> > > > $this->set('friends', $this->User->Friends->Profiles->findAll());
> > > > This returns every profile in the system, not just those for the
> > > > user's friends.
>
> > > Your controller isn't tied to usingjust one Model, the $uses array of
> > > the Controller can specify all the models you want:
>
> > > var $uses=array('Profiles','User');
>
> > > then you can start all your queries from these models, no need to
> > > chain them as above.
>
> > > > how to access the specific data I want without doing 2 or 3
> > > > levels of recursion on a find() for the user.
>
> > > There are various ways to tweak Cake queries, like setting the
> > > recursion level, or which tables to join for any particular query.
>
> > > Jan 18, 11:09 pm, Chris Wade <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to