Bug Report #784

limit() no longer works correctly through ORM

Added by Drarok - over 3 years ago. Updated over 3 years ago.

Status:Closed Start date:
Priority:Normal Due date:
Assignee:Woody Gilk % Done:

0%

Category:Libraries:ORM
Target version:-
Resolution:worksforme Points:

Description

The following code:
$filedb = new File_Model; // This is an ORM subclass.
$files = $filedb->orderby('created', 'desc')->limit(15, 30)->find_all();

Results in the incorrect query:
SELECT @files.* FROM files ORDER BY created DESC LIMIT 0, 15@

Using >limit()>find() also doesn't work correctly. I've been shown the new way is to use ->find_all($limit, $offset), but if this is the case, the documentation needs updating, and ->limit needs to fail.

The above method used to work (this was presumably before ORM2).

History

Updated by Drarok - over 3 years ago

Damn, formatting broke.

I believe that limit() needs to be fixed to allow the following to work:

// Where files is a one-to-many relationship...
$files = $tag->where('hidden', 0)->limit(15, 30)->files;

The above code gives a query saying LIMIT 0, 15.

Updated by Kyle - over 3 years ago

  • Status changed from New to Closed
  • Resolution set to worksforme

I haven't been having a problem with limit().

I think your problem is you are running more then 1 query on the files related object.

Ex:

1 <?php
2 // Example of guessing your first query
3 $firstfiles = $tag->where('hidden',0)->limit(0,15)->files;
4 // Other code here
5 $secondfiles = $tag->where('hidden',0)->limit(15,30)->files;
6 

The problem is you need to unset the first files object, before the 2nd query.

unset($tag->files); before the 2nd query should help you out.

The reason this is happening is because in the ORM, it simply checks to see if the object is already set. If it is, ORM returns it. So the 2nd query is never being made to find the new files.

Also available in: Atom PDF