Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM : Limiting a related model?
  • I have been searching every where for a solid answer but nothing came up. Question:
    I have a basic Model_Post and Model_Comment. A Post has many comments and a comment belongs to a post.
    The issue is that when I fetch(tried both lazy and eager loading) the Model_Post I cannot impose a limit on to the Model_Comment. I realise that eager loading uses joins and joins don't support limits as far as I know.
    $view->posts = Model_Post::find('all', 
          array(
           'limit' => 5,
           'related' => array(
            'comments' => array(
             'order_by' => array('created_at' => 'desc'),
             'limit' => 2
            )
           ), 
           'order_by' => array('created_at' => 'desc'))
         );
    

    Since I want to be able to utilize the pagination on the Model_Comments but still using the orm relations. My previous version was built with the query builder with joins and multiple queries. Now I was thinking if it's possible to force the orm to use multiple queries instead of joins. Yes it would be less efficient but at least I will keep all of the relations going since they do get somewhat complicated. Thanks for any insight on this,
    Daniel
  • I also want to achieve the same thing but looks like this doesn't work. It always returns an empty record-set! It creates sub-queries but looks like not in the right way...
  • I was just having the exact same issue. The solution is to use rows_limit instead of limit.

Howdy, Stranger!

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

In this Discussion