[CDBI] order_by with joined tables?

Alan alan at ufies.org
Thu Nov 2 19:14:27 GMT 2006


Hey all.  I'm wondering if there's a way to order by a field in a joined
table.  For example, I have:

table company
        id
        name
table people
        id
        fullname
        company_id

package Company;
...
package Person;
...
Person->has_a( company_id => 'Company' );

I can of course get results sorted by any field in the Person class:

@array = Company->search_where( { fullname => 'alan' }, { order_by =>
'fullname' } );

However what I want to do is order by the name of the company in the
join because the order by company_id doesn't work.  

Putting 'company.name' or 'name' in the order_by just bails out.  Using
pure SQL I'd just join the tables together and then order by the company
name with something like:

select name,fullname 
from people join company on company.id = people.company_id
where blah 
order by company.name

However I don't know how to get this into the nice CDBI framework :(

Any pointers appreciated.

TIA

Alan

-- 
Alan <alan at ufies.org> - http://arcterex.net
--------------------------------------------------------------------
"Backups are for people who don't pray."                 -- big Mike



More information about the ClassDBI mailing list