Wednesday, June 2, 2010

Re: Order problem with deep association

Not sure if I understood the question, but if you want Alix to appear
before Shantam you can sort the assignment array with Set::sort

Assuming your data array is called $shifts, you could do it like this

foreach($shifts as $i => $shift) {
$shifts[$i]['Assignment'] = Set::sort($data['Assignment'],
'{n}.Person.name', 'asc');
}

On Jun 2, 5:52 am, shantamg <jason.galu...@gmail.com> wrote:
> Shift hasMany Assignment
> Assignment belongsTo Person, Shift
> Person hasMany Assignment
>
> So if I do this:
>
> $this->Shift->find('all', array(
>     'contain' => 'Assignment.Person'
> ));
>
> I get something like this:
>
> Array
> (
>     [0] => Array
>         (
>             [Shift] => Array
>                 (
>                     [id] => 1
>                     etc...
>             [Assignment] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 1
>                             [person_id] => 1
>                             [shift_id] => 1
>                             etc...
>                             [Person] => Array
>                                 (
>                                     [id] => 1
>                                     [name] => Shantam
>                                     etc...
>                                 )
>                         )
>                     [1] => Array
>                         (
>                             [id] => 2
>                             [person_id] => 2
>                             [shift_id] => 1
>                             etc...
>                             [Person] => Array
>                                 (
>                                     [id] => 2
>                                     [name] => Alix
>                                     etc...
>                                 )
>                         )
>                     etc....
>                 )
>         )
> )
>
> So there's only ever one Person per Assignment. How can I order the
> Assignments by Person.name?
>
> Thanks,
> Jason

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: