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