#929 ✓resolved
Deleted User

model loading problem when using non :default connection name

Reported by Deleted User | June 27th, 2009 @ 12:22 PM | in 0.10.0

Illustrated by:

class User
  include DataMapper::Resource
  
  property :id, Serial
end

DataMapper.setup(:default, "sqlite3://test_legacy.db")
User.auto_migrate!

user = User.create!
user = User.create!

default_all = User.all

class LegacyUser
  include DataMapper::Resource

  def self.default_storage_name
    'user'
  end
  
  repository(:legacy) do
    property :id, Serial
  end
end

DataMapper.setup(:legacy, "sqlite3://test_legacy.db")

legacy_all = nil
repository(:legacy) do

  legacy_all = LegacyUser.all
end

puts default_all.inspect # => [#<User @id=1>, #<User @id=2>]
puts legacy_all.inspect  # => [#<LegacyUser @id=1>, #<LegacyUser @id=1>]

note that legacy_all contains two records with @id=1.

The problem seems to be in the lodd method:

dm-core-0.10.0/lib/dm-core/model.rb:407

resource = if (key_values = record.values_at(*key)).all?
  identity_map = repository.identity_map(model)
  identity_map[key_values]
end

as the repository name isn't being passed to the key method (so it's using the default name). Changing this to:

resource = if (key_values = record.values_at(*key(repository.name))).all?
  identity_map = repository.identity_map(model)
  identity_map[key_values]
end

fixes the prob.

Attached is a script which can be run to show if the problem is fixed or not

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

Referenced by

Pages