Friday, June 4, 2010

Re: Order problem with deep association

yes, but now we're back to the same problem: we are sorting only the
one person record inside of each assignment, and we want to sort the
assignments. the programatic way you suggested works (i included what
I did below), but unlike contain, Set::sort() only takes one sort
parameter.

if (isset($area['Shift'])) {
foreach($area['Shift'] as &$shift) {
$shift['Assignment'] = Set::sort(
$shift['Assignment'],
"{n}.Person.resident_category_id",
"asc"
);
}
}


On Jun 4, 1:04 pm, vekija <vedran.konto...@gmail.com> wrote:
> Sorry about that, acidently posted before I finished :)
>
> $this->Shift->find('all', array(
>     'contain' => array(
>         'Assignment' => array(
>             'Person' => array(
>                 'order' => 'Person.category_id ASC, Person.name ASC'
>             )
>         )
>     )
> ));
>
> On Jun 4, 11:29 am, shantamg <jason.galu...@gmail.com> wrote:
>
>
>
> > yes, that about does it.. but what if i want to order by two fields?
> > something like: Person.category_id asc, Person.name asc
>
> > On Jun 2, 12:21 am, vekija <vedran.konto...@gmail.com> wrote:
>
> > > 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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate