#1354 accepted
bcrouse

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

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 »

Attachments

Pages