Ticket #784 (closed Bug: worksforme)

Opened 3 months ago

Last modified 3 months ago

limit() no longer works correctly through ORM

Reported by: Drarok Owned by: Shadowhand
Priority: minor Milestone:
Component: Libraries:ORM Version: SVN HEAD
Keywords: orm limit Cc:

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).

Change History

Changed 3 months ago by Drarok

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.

Changed 3 months ago by Zoxive

  • 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:

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

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.

Note: See TracTickets for help on using tickets.