Shawn Dellysse Wed Feb 23 17:15:43 -0500 2011

Subject: Need help with advanced finders

Tables:

types: (id, type_name)
files: (id, type_id, account_id, attr1, attr2, ... attr15)
accounts: (id, username)

What I'm trying to do would be written like this in MySQL:

SELECT *
FROM accounts
INNER JOIN files ON accounts.id = files.account_id
INNER JOIN types ON files.type_id = types.id
ORDER BY types.type_name;

Can I do something like this:

Account::find($account_id)->files->all(array('order' => 'types.type_name'));

Shawn Dellysse Mon Feb 28 10:31:59 -0500 2011

What I ended up coming up with was

$this->files = File::all(array(
'joins' => array('account', 'type'),
'conditions' => array('account_id = ?', $account->id),
'order' => 'types.type',
));

(1-1/1)