#507 ✓resolved
Arkadiusz Hiler

offset causes wrong database request

Reported by Arkadiusz Hiler | August 2nd, 2008 @ 07:15 PM

tested on edge

whenever you try to .count or to load lazy property when :offset id used dm creates wrong request to database

>> Ticket.all(:project_id => 1, :offset => 2, :limit => 2 ).each {|x| puts x.body}
Sun, 03 Aug 2008 00:11:37 GMT ~ debug ~ SELECT `id`, `scope_id`, `user_id`, `project_id`, `created_at`, `updated_at`, `state` FROM `tickets` WHERE `project_id` = 1 ORDER BY `id` LIMIT 2 OFFSET 2
Sun, 03 Aug 2008 00:11:37 GMT ~ debug ~ SELECT `body`, `id` FROM `tickets` WHERE `project_id` = 1 AND `id` IN (57, 58) ORDER BY `id` LIMIT 2 OFFSET 2
nil
=> []
>> Ticket.all(:project_id => 1, :offset => 2, :limit => 2 ).count
Sun, 03 Aug 2008 00:12:19 GMT ~ debug ~ SELECT COUNT(*) FROM `tickets` WHERE `project_id` = 1 LIMIT 2 OFFSET 2
=> nil
>> Ticket.all(:project_id => 1, :offset => 2, :limit => 2 ).size
Sun, 03 Aug 2008 00:12:21 GMT ~ debug ~ SELECT `id`, `scope_id`, `user_id`, `project_id`, `created_at`, `updated_at`, `state` FROM `tickets` WHERE `project_id` = 1 ORDER BY `id` LIMIT 2 OFFSET 2
=> 2

above example is from MySQL, same on Postgres:

>> blahs = Blah.all(:limit => 2, :offset => 2)
Sat, 02 Aug 2008 23:48:47 GMT ~ debug ~ SELECT "id", "rank" FROM "blahs" ORDER BY "id" LIMIT 2 OFFSET 2
=> [#<Blah id=3 rank=16 text=<not loaded>>, #<Blah id=4 rank=24 text=<not loaded>>]
>> blahs.each { |b| puts b.text } 
Sat, 02 Aug 2008 23:48:52 GMT ~ debug ~ SELECT "text", "id" FROM "blahs" WHERE "id" IN (3, 4) ORDER BY "id" LIMIT 2 OFFSET 2
nil

probably sqlite3 is affected too

there should be no OFFSET when dm tries to load lazy properties or count them

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Attachments

Pages