Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Query Building with ORM
  • Hi guys, This is quite tough to explain so I'll try as best I can. Given the following code:
    $tweets = Model_Tweet::find()->related( "buckets", array( 'where' => array( 'id' => $id ) ) ->order_by( 'tweet_datetime', 'desc' )->limit( $this->limit )->offset( $this->offset )->get();
    

    I was expecting to get back 20 Tweets which belonged to Bucket 2. The problem is, the results I'm getting back are varied and after following through the SQL generation, it seems that specifying an Offset and a Limit is causing the problem. In this example, my offset was 0 and limit was 20 but if I removed that, I got the expected data back which was 37 Tweets which belonged to Bucket 2. It seems that specifying an offset/limit tells the ORM to use a subquery, which seems to be the problem. This is the SQL thats generated, as you can see, it does a subquery for the sole purpose of adding a limit and offset but that's not what I intended. This is the SQL I was hoping for, just simply appending a Limit and Offset to the end of the query. I'm not sure if this is a bug or something wrong with my implementation but I appreciate any guidance/help. For now, I'm just using the amended query with the Query Builder class to get the results I need.
  • You can do the latter by using rows_offset() and rows_limit(), instead of limit()/offset() which impose the limit/offset on the base model's table. I'm not going to go into that again, there's about a 100 earlier explanations I did on this topic in both the issue tracker and the forums - one was at most 2 weeks ago iirc.
  • Thanks for the advice, I'll try that.
  • I've googled this page.

    now it's rows_limit() rows_offset()
  • I assume it was a typo in Jelmers email, as it has always been with an 's'. I've corrected Jelmers post.

Howdy, Stranger!

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

In this Discussion