Sorting the primary result on read doesn't make any sense, because
read uses the primary key to find ONE record, which will always be
unique.

So presumably you mean sorting the secondary finds (associations),
like your 'Followup'. Well, the easiest way is to set the 'orderBy'
attribute in your association directly:

class Note extends AppModel {
  var $hasMany = array(
    'Followup' => array(
      'className' => 'Followup',
      'orderBy' => 'Followup.created DESC'
    )
  );
}

Now when you do a find/findAll on Note with recursive 1 or more [note:
read() just calls find() internally -- which in turn calls findAll()],
your associated Followup results will be sorted however you like.

If you need to perform a one-off find will a different sort order,
just change the association data:

(assuming you're in a controller)
// Store old order by
$oldOrderBy = $this->Note->hasMany['Followup']['orderBy'];
// Change it
$this->Note->hasMany['Followup']['orderBy'] = "Followup.created ASC";
// Read
$foo = $this->Note->read(null, $id);
// Change it back
$this->Note->hasMany['Followup']['orderBy'] = $oldOrderBy;

On Oct 18, 8:53 am, jwerd <[EMAIL PROTECTED]> wrote:
> Is there anyway to do sorting with simply using this->read?
>
> $this->set('note', $this->Note->read(null, $id));
>
> or do I have to change it to something else like findAll?
>
> Also I use recursive = 2 and I actually want an association called
> Followup sorted by it's created column.  Everything works fine as it
> is, I'm just wondering whether I can pass some argument before I do
> the this->read to sort the Followup.created column?
>
> Please let me know if you need more understanding of this.  It's late
> here :P


--~--~---------~--~----~------------~-------~--~----~
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