
An object accessed from an association is un-savable
Reported by Chris Van Pelt | June 22nd, 2009 @ 08:00 PM | in 0.10.0
Not sure if this has been discovered already... If I access the
user object from the association it isn't saved, even though it's
flagged as dirty and save
returns true. If I grab the
user using User.get or User.first, it works fine.
require 'rubygems'
require 'dm-core'
class User
include DataMapper::Resource
property :id, Serial
property :credits, Integer, :default => 0
has n, :things
end
class Thing
include DataMapper::Resource
property :id, Serial
belongs_to :user
end
DataMapper.setup(:default, 'sqlite3::memory:')
DataMapper.auto_migrate!
puts "User pulled by association:\n============="
t = Thing.create(:user => User.create)
u = t.user
u.credits += 10
puts "User dirty? #{u.dirty?}"
puts "User saved with 10 credits? #{u.save}"
puts "User credits: #{u.reload.credits}"
puts "\nUser pulled from scratch:\n============"
u = User.first
u.credits += 10
puts "User dirty? #{u.dirty?}"
puts "User saved with 10 credits? #{u.save}"
puts "User credits: #{u.reload.credits}"
Outputs:
User pulled by association:
=============
User dirty? true
User saved with 10 credits? true
User credits: 0
User pulled from scratch:
============
User dirty? true
User saved with 10 credits? true
User credits: 10
Comments and changes to this ticket
-
Dan Kubb (dkubb) June 22nd, 2009 @ 10:01 PM
- Assigned user set to Dan Kubb (dkubb)
- State changed from new to resolved
This works fine with dm-core/next, and dm-core 0.10 RC1. Marking as resolved.
-
Chris Van Pelt June 23rd, 2009 @ 12:45 AM
Awesome Dan! Good to know :)
Do you consider dm-core RC1 to be stable enough for production use? I assume it's tighter than 0.9.11 with all of the hot new specs.
-
Dan Kubb (dkubb) June 23rd, 2009 @ 01:18 AM
@Chris: I know of several people who are using RC1 in production settings, one of them quite a large system. As with all software there are still known bugs we are working though, but I would consider it more stable than 0.9.x.
Also bugs in 0.10 will be fixed much more quickly than 0.9, which really would only get critical fixes from me. Of course I'd not prevent anyone from backporting fixes to 0.9, but most of my effort is in making sure 0.10 is stable.
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 »