[Solar-talk] How can i implement ordering on a _belongsTo or _hasMany relationship

Raymond Kolbe rkolbe at gmail.com
Fri Feb 15 21:19:56 CST 2008


To access the employee information through the department model, you would
do:

$employee = $department->fetchAll($params);
$employee->employees->name; // this will return the name of the employee

On Feb 15, 2008 10:18 PM, Raymond Kolbe <rkolbe at gmail.com> wrote:

> Is there any way i can implement an ORDER BY clause against those employee
> > records?
>
>
> $params = array(
> 'order' => 'employees.id'
> )
>
> $department->fetchAll($params);
>
> This will order your results on the employees.id column. Is this what you
> are looking for?
>
> On Feb 15, 2008 10:41 AM, Cruz, Darwin <Darwin.Cruz at gd-ais.com> wrote:
>
> >  I'm using the Solar models and need to implement a order by against a
> > database table column that i'm querying through a
> >
> >  _belongsTo or _hasMany relationship.
> >
> > So if i have a DEPARTMENT model that has many EMPLOYEES my DEPARTMENT
> > model has the following relationship defined.
> >
> >         $this->_hasMany('employees', array(
> >             'foreign_class' => 'Project_Models_Employee',
> >             'foreign_key'   => 'department_id',
> >         ));
> >
> > So if i want to find out all the employess in a specific department i
> > cause do the following $myDepartment->employees to get all the employee
> > records.  Is there any way i can implement an ORDER BY clause against those
> > employee records?
> >
> > Thanks.
> >
> > Darwin Cruz
> >
> > _______________________________________________
> > Solar-talk mailing list
> > Solar-talk at lists.solarphp.com
> > http://mailman-mail3.webfaction.com/listinfo/solar-talk
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman-mail3.webfaction.com/pipermail/solar-talk/attachments/20080215/9e7fb56a/attachment.html


More information about the Solar-talk mailing list