#1084 ✓resolved
Jacques Crocker

Binding Mismatch Error when merging :conditions

Reported by Jacques Crocker | October 8th, 2009 @ 12:19 AM

Combining multiple :conditions on class level selectors seems to cause DataMapper 0.10 to blow up. Verified this is still the case on master (as of October 7, 2009 - 2aac5cfc15143062b1efecf1c9b195d7cd6e42e8).

Here is the code that will replicate the bug. This same snippet seems to work fine on DataMapper 0.9.11

DataMapper::Logger.new(STDOUT, :debug) 
DataMapper.setup(:sqlite3, 'sqlite3::memory:')
DataMapper::Repository.adapters[:default] =  DataMapper::Repository.adapters[:sqlite3]

class Post
  include DataMapper::Resource

  property :id, Serial
  property :name, String
  property :description, Text

  def self.alphabetical
    all(:order => [:name.desc])
  end

  def self.with_name
    all(:conditions => ["name IS NOT NULL"])
  end

  def self.by_body(body)
    all(:conditions => ["description LIKE ?", "%#{body}%"])
  end

end

Post.auto_migrate!

puts Post.alphabetical.with_name.by_body("blah").inspect

Here is the stack trace:

 ~ Binding mismatch: 1 for 0
/Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/data_objects-0.10.0/lib/data_objects/command.rb:73:in `escape_sql': Binding mismatch: 1 for 0 (ArgumentError)
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:149:in `execute_reader'
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:149:in `read'
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:287:in `with_connection'
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:145:in `read'
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/dm-core-0.10.2/lib/dm-core/repository.rb:141:in `read'
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/dm-core-0.10.2/lib/dm-core/collection.rb:1001:in `lazy_load'
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/extlib-0.9.14/lib/extlib/lazy_array.rb:451:in `map'
    from /Users/jc/.rvm/gems/ruby/1.8.7-testdm/gems/dm-core-0.10.2/lib/dm-core/collection.rb:902:in `inspect'
    from dmproblem.rb:35

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

Tags

Referenced by

Pages