#807 ✓resolved
Deleted User

finder scoping not behaving as expected

Reported by Deleted User | February 26th, 2009 @ 02:43 PM

well, to me anyway - code below illustrates the issue:

require 'rubygems'
require 'ruby-debug'
gem 'dm-core', '0.9.10'
require 'dm-core'

DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')

class Member
  include DataMapper::Resource
  property  :id,                Serial
  def self.subscribed
    all(:id => [1, 2, 3])


5.times { Member.new.save }

puts Member.subscribed.inspect
# SELECT "id" FROM "members" WHERE ("id" IN (1, 2, 3)) ORDER BY "id"
# => [#<Member id=1>, #<Member id=2>, #<Member id=3>]

puts Member.subscribed.get(5).inspect
# SELECT "id" FROM "members" WHERE ("id" = 5) ORDER BY "id" LIMIT 1
# => #<Member id=5>

I was expecting the last query to be along the lines of: SELECT "id" FROM "members" WHERE ("id" IN (1, 2, 3)) AND ("id" = 5) ORDER BY "id" LIMIT 1

I'm sure things used to work like this, but I couldn't re-create things when it did work.

And (sorry, but) I've not tested this with dm-next as I'm a bit reluctant to mess with my setup what with all the 'already activated' problems it usually results in with the merb project I'm working on.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 26th, 2009 @ 05:00 PM

    • Assigned user set to “Dan Kubb (dkubb)”
    • State changed from “unconfirmed” to “resolved”

    I can confirm this is resolved in dm-core/next. Marking this ticket as resolved.

    The SQL query generated for the last statement was:

    SELECT "id" FROM "members" WHERE "id" = 5 AND "id" IN (1, 2, 3)

    Attached is a script with all the output when the query runs.

    I can understand your reluctance to mix and match dm-core and dm-more plugins of different versions. It will likely not work even if there are tiny version differences, and given that we're jumping from the 0.9 series to 0.10 most dm-more gems will most certainly not work since many of them rely on private behavior in dm-core that has changed.

    Somebee has a dm-more fork, and in his next branch we're slowly updating each dm-more plugin to be compatible with 0.10. We could use a hand though, so if you're interested in resolving this in your app feel free to ask somebee for commit rights or fork it and start sending pull requests to him or myself (I have commit rights to his repo too). Once all of the plugins are updated I'll merge it into the mainline, but I don't want to do that until they all work as it will just cause more confusion.

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