$options['contain'] = array(
'Team' => array(
'User'
)
);
That should give you the Team for the specified user, and the Users of
the Team.
I assume here that your models are associated as:
User hasAndBelongsToMany Team
Enjoy,
John
On Oct 31, 2:06 pm, "marco.rizze...@gmail.com"
<marco.rizze...@gmail.com> wrote:
> I don't know the team_id I kow user_id.
> I would find all users of all teams which user_id belongs.
> I ask me if it is possible with only one find operation using
> contanaible behaviour.
>
> On 31 Ott, 11:27, John Andersen <j.andersen...@gmail.com> wrote:
>
> > That is not what you are showing with your code.
> > This part sets the condition of a user with an id, not a team with an
> > id.
> > Try to find from the team side, not the user side, if you know the
> > team id!
> > Example:
> > $this->Team->find(...)
>
> > or if you don't have the Team model in the controller:
> > $this->User->Team->find(...)
>
> > Enjoy,
> > John
>
> > On Oct 31, 12:13 pm, "marco.rizze...@gmail.com"
>
> > <marco.rizze...@gmail.com> wrote:
> > > Yes I try to get all the users of the team with id=4 but I don't get
> > > anything.
> > > Where do i mistake?
>
> > > On 30 Ott, 20:42, John Andersen <j.andersen...@gmail.com> wrote:
>
> > > > You are using find('first', $options), so you only get one record!
> > > > And the one record will be the one which has a team with a user!
> > > > You don't get the team!
>
> > > > I am guessing - are you trying to get all the users in the first team
> > > > for the specified user?
> > > > Enjoy,
> > > > John
>
> > > > On Oct 30, 6:30 pm, "marco.rizze...@gmail.com"
>
> > > > <marco.rizze...@gmail.com> wrote:
> > > > > Hi
> > > > > I use containable behaviour, but I don't get all data that I have
> > > > > requested
> > > > > My code is :
>
> > > > > $options['fields'] = array('User.*');
> > > > > $options['conditions'] = array('User.username' => $user_id);
> > > > > $options['contain'] = array(
> > > > > 'Organization' => array(
> > > > > 'fields'=>array('Team.*'),
> > > > > 'User' => array(
> > > > > 'fields' => array('User.*')
> > > > > )
> > > > > )
> > > > > );
> > > > > pr($this->User->find('first',$options));
>
> > > > > But I get only :
>
> > > > > Array
> > > > > (
> > > > > [User] => Array
> > > > > (
> > > > > [id] => 1
> > > > > .......
> > > > > .......
> > > > > )
>
> > > > > [Team] => Array
> > > > > (
> > > > > [0] => Array
> > > > > (
> > > > > [id] => 4
> > > > > .......
> > > > > .......
> > > > > [UsersTeams] => Array
> > > > > (
> > > > > [id] => 1
> > > > > [user_id] => 1
> > > > > [team_id] => 4
> > > > > )
> > > > > )
> > > > > )
> > > > > )
>
> > > > > I don't get all users that are inside team
>
> > > > > Between User and Team there is a hasAndBelongsToMany relation.
>
> > > > > How can I do to get also all users that are in team?
>
> > > > > Many Thanks
> > > > > Marco
--~--~---------~--~----~------------~-------~--~----~
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:
Post a Comment