Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Order by relation
  • Is there a way to order by a relations property? For example: Model Posts has many Comments. When I query Posts from the Model internally, can i say it will need to order by the Comments.created at?
  • Never mind, I am totally stupid. You can use the related option in you options. 

    However, I have a following problem: 

    I have declared conditions in the Comments model. When using the related option in the Posts model, it throws an error:

    Fuel\Core\PhpErrorException [ Notice ]: Undefined offset: 2


    it has to do with 

    PKGPATH/orm/classes/hasmany.php @ line 112

    is_string($condition[2]) and $condition[2] = \Db::quote($condition[2], $model['connection']);
     

    Can anybody explain my how to properly use both contiditions on related Models and using the related option in a parent class?
  • Never mind again, it was a type error in the condition array. I declared it like this: 

    array('object_type', 5);

    Which should have been: 

    array('object_type', '=', '5');

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion