Try this. The code is dirty so you should refactor it :)

            //sort assignments by person category
            $data['Assignment'] = Set::sort($data['Assignment'],
'{n}.Person.category', 'ASC');

            //group assignments by person category
            //person name is used here as a array key as I'm not sure
how to make this with numeric keys :)
            $data['Assignment'] = Set::combine($data['Assignment'],
'{n}.Person.name', '{n}', '{n}.Person.category');

            $assignments = array();

            foreach($data['Assignment'] as $i=>$group) {

                // revert back tu numeric
keys :)
                $data['Assignment'][$i] = array_values($group);

                // sort array by person name
                $data['Assignment'][$i] = Set::sort($data['Assignment']
[$i], '{n}.Person.name', 'ASC');
                $assignments = array_merge($assignments,
$data['Assignment'][$i]);
            }

            $data['Assignment'] = $assignments;


Going to bed.

Cheers


On Jun 4, 11:36 pm, shantamg <[email protected]> wrote:
> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 [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