
Chaining class finder methods generating incorrect query
Reported by bcrouse | July 6th, 2010 @ 06:24 PM | in 1.1.1
class NewModel
include DataMapper::Resource
property :id ,Serial
property :use_starts_at, DateTime
property :use_ends_at, DateTime
def self.usable_after(time)
all(:use_starts_at => nil) | all(:use_starts_at.lt => time)
end
def self.usable_before(time)
all(:use_ends_at => nil) | all(:use_ends_at.gt => time)
end
end
NewModel.auto_upgrade!
NewModel.usable_after(Time.now).usable_before(Time.now)
# Expected SQL:
# SELECT `id`, `use_starts_at`, `use_ends_at`
# FROM `new_models`
# WHERE
# (`use_ends_at` IS NULL OR `use_ends_at` > '2010-07-06 15:42:18')
# AND
# (`use_starts_at` IS NULL OR `use_starts_at` < '2010-06-05 15:42:18')
#
# Generated SQL:
# SELECT `id`, `use_starts_at`, `use_ends_at`
# FROM `new_models`
# WHERE (`use_starts_at` IS NULL OR `use_starts_at` < '2010-07-06 15:42:18')
Comments and changes to this ticket
-
Jonathan Stott (namelessjon) July 17th, 2010 @ 01:41 PM
- State changed from new to confirmed
I can confirm this is a bug. See the attached standalone reproduction.
-
Dan Kubb (dkubb) July 28th, 2010 @ 01:01 AM
- Assigned user set to Dan Kubb (dkubb)
- State changed from confirmed to accepted
- Milestone set to 1.0.2
- Milestone order changed from 196227 to 0
-
Dan Kubb (dkubb) July 28th, 2010 @ 12:50 PM
This bug is caused by the fact that DM doesn't treat the following statements as equivalent:
all(...) & all(...) all(...).all(...)
Although I think it probably should. Chaining together #all statements should result in them being AND'd together.
I do recall a few months ago when I tried to make this work, but I wasn't able to. I will try again and see what I can do.
-
Dan Kubb (dkubb) September 7th, 2010 @ 08:54 PM
- Milestone changed from 1.0.2 to 1.1
- Milestone order changed from 4 to 0
-
Bernerd Schaefer January 4th, 2011 @ 10:39 AM
Has there been any progress on this? It's currently a major blocker for me attempting to migrate a project from Mongoid to DM, but my knowledge of DM internals if far too out-of-date to figure out how to patch this.
-
Bernerd Schaefer January 7th, 2011 @ 03:51 AM
For what it's worth, the following gist contains my workaround for this issue: https://gist.github.com/769297
-
Dan Kubb (dkubb) March 16th, 2011 @ 10:41 PM
- Milestone changed from 1.1 to 1.1.1
- Milestone order changed from 3 to 0
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »