
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
-
Dan Kubb (dkubb) July 16th, 2009 @ 02:12 AM
- Assigned user set to Dan Kubb (dkubb)
- State changed from new to accepted
-
Dan Kubb (dkubb) July 16th, 2009 @ 03:29 AM
- State changed from accepted to resolved
(from [23cc58a4c8214d1153085240861903c165f71066]) Pass in repository name into Model#serial and Model#key when necessary
[#929 state:resolved] http://github.com/datamapper/dm-core/commit/23cc58a4c8214d115308524...
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 »
People watching this ticket
Attachments
Referenced by
-
929 model loading problem when using non :default connection name [#929 state:resolved] http://github.com/datamapper/dm-co...