#681 ✓resolved
Jamie Macey

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

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

Pages