
Saving through a m:1 association can silently fail
Reported by Greg Campbell | May 21st, 2009 @ 05:48 PM
See the script below: saving a resource associated via belongs_to appears not to write anything to the database.
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default, 'sqlite3::memory:')
class Zoo
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :animals
end
class Animal
include DataMapper::Resource
property :id, Serial
property :species, String
belongs_to :zoo
end
DataMapper.auto_migrate!
Zoo.create(:name => "old").animals.create(:species => "tiger")
animal = Zoo.first.animals.first
animal.zoo.name = "new!"
puts animal.zoo.save # "true"
# The save above did not persist anything to the DB
puts animal.zoo.name # "new!"
puts animal.zoo.dirty? # "true"
puts animal.zoo.reload.name # "old"
Comments and changes to this ticket
-
Greg Campbell May 21st, 2009 @ 05:50 PM
Sorry for the formatting; Lighthouse desperately needs either a way to edit tickets after they've been created or a way to preview tickets before they're created.
-
-
Dan Kubb (dkubb) May 21st, 2009 @ 06:55 PM
- State changed from unconfirmed to resolved
Greg: by "never mind" do you mean you resolved the issue, or that you fixed the formatting?
I just tried this with the dm-core/next branch, and it passes, so I am marking this ticket as resolved. The next minor release of DataMapper will be from the dm-core/next branch, which will be happening shortly.
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 »