
Paranoid and #attributes reverts updates
Reported by Jamie Macey | December 1st, 2008 @ 02:30 PM
Model definition:
class Profile
include DataMapper::Resource
property :id, Integer, :serial => true
property :login, String, :size => 30
property :deleted_at, DataMapper::Types::ParanoidDateTime
end
Example code:
pr = Profile.get(1)
pr.attributes
pr.reload
pr.attributes
Queries Run:
~ SELECT `id`, `login`, `user_id` FROM `profiles` WHERE (`deleted_at` IS NULL) AND (`id` = 1) ORDER BY `id` LIMIT 1
~ SELECT `deleted_at`, `id`, `login`, `user_id` FROM `profiles` WHERE (`id` = 1) ORDER BY `id`
~ SELECT `deleted_at`, `id`, `login`, `user_id` FROM `profiles` WHERE (`id` IN (1)) ORDER BY `id`
When I run this with deleted_at active, the first call to attributes does an extra select and overwrites the attributes. Also, after I reload the model, attributes no longer does queries. Without deleted_at, I only get queries on the get and reload.
This is problematic for people who naively compare #original_values and #attributes hashes to see if there are any differences in fields. I was doing that to check for updates on city/state/country/zip, and if there are changes fire off a geocode request.
Using send(:city) instead of attributes[:city] is a functional workaround for the time being, but I'd rather not send() if I can avoid it.
Comments and changes to this ticket
-
Dan Kubb (dkubb) December 4th, 2008 @ 03:51 AM
- State changed from new to accepted
-
Jonathan Stott (namelessjon) February 22nd, 2009 @ 09:17 AM
- Tag changed from paranoid, property to one_file_test, paranoid, property
- State changed from accepted to resolved
This isn't an issue in 0.10.0 (see attached one file test)
ParanoidDateTime seems to be a lazy property, so it does trigger a fetch on attributes (which gets all of them, obviously), but this fetch doesn't overwrite any other attributes.
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 »