Setting a default order_by in related models using fuelPHP

Notes on the system i’m building:

A user has many sets of related data, one set being a list of quote item rates which get used (to form a dropdown) when a user is creating a quote item, this list of course needs to be ordered correctly, as the user can manage these items, deleting, adding etc)

You can set conditions on the relation.

So in the User model, the defined relation looks like so:

protected static $_has_many = array(
'quoteitemrates' => array(
'key_from' => 'id',
'model_to' => 'Model_QuoteItemRate',
'key_to' => 'user_id',
'cascade_save' => true,
'cascade_delete' => false,
'conditions' => array(
'order_by' => array(
'name' => 'ASC'

Very good, every time i access $user->settings->quoteitemtypes, they are in the right order!

Leave a Reply

Your email address will not be published. Required fields are marked *