[Solar-talk] How can i implement ordering on a _belongsTo
or_hasMany relationship
Kilbride, James P.
James.Kilbride at gd-ais.com
Tue Feb 19 08:11:24 CST 2008
Not exactly Raymond. More looking to order them by a column in the
employees table, such as something like employee name. Say I'm doing a
hierarchal set of drop downs. The first drop down has the departments
ordered by name. Not hard, I just put that order by in my fetchall. But
now when I'm building the second dimension of my arrays I want to order
the employees for that department by their names. I can do it by calling
a fetch on the employees table based on the department id, for example,
but then I'm not using the fact that there is a relationship on the
department model at all. I've completely ignored that fact. What I want
is some way to pass the relationship a series of parameters, like a
fetch, when I call it so it can reorder them for me if possible. I can
of course do the sorting after i get the results from the database using
php's sort but it would certainly be nicer to get the order from the DB.
James Kilbride
________________________________
From: solar-talk-bounces at lists.solarphp.com
[mailto:solar-talk-bounces at lists.solarphp.com] On Behalf Of Raymond
Kolbe
Sent: Friday, February 15, 2008 10:19 PM
To: solar-talk at lists.solarphp.com
Subject: Re: [Solar-talk] How can i implement ordering on a _belongsTo
or_hasMany relationship
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/20080219/663a23c9/attachment.html
More information about the Solar-talk
mailing list