
[PATCH] Model.load returns wrong records without primary keys
Reported by maiha | December 14th, 2008 @ 03:22 PM
Model.all returns all same records when the model has no primary keys.
# select * from registries;
key | val
-----+-----
xxx | 1
yyy | 2
class Registry
include DataMapper::Resource
property :key, String
property :val, String
end
irb(main):001:0> Registry.all
=> [#<Registry key="xxx" val="1">, #<Registry key="xxx" val="1">]
This is because Query#key_property_indexes returns [] when there are no primary keys, although Model.load expects nil.
Comments and changes to this ticket
-
maiha December 14th, 2008 @ 03:27 PM
- Tag changed from bug, dm-core, patch to bug, dm-core, patch
paste ruby code again
class Registry include DataMapper::Resource property :key, String property :val, String end Registry.all.each do |r| p [r.key, r.val] end ["xxx", "1"] ["xxx", "1"]
-
Dan Kubb (dkubb) January 8th, 2009 @ 05:16 AM
- State changed from unconfirmed to not-applicable
A constraint of DM is that each model must have at least one key. This may be relaxed in the future, but for now it simplifies the logic in several places.
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 »