
In 0.10, new on associations with STI parent sets incorrect foreign key property, causing object to be unsaveable
Reported by Greg Campbell | June 23rd, 2009 @ 05:33 PM | in 0.10.0
Probably easiest to demonstrate in a script:
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default, 'sqlite3::memory:')
class Place
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
end
class Zoo < Place
has n, :animals
end
class Animal
include DataMapper::Resource
belongs_to :zoo
property :id, Serial
property :name, String
end
DataMapper.auto_migrate!
zoo = Zoo.create
donkey = zoo.animals.new(:name => "donkey")
# This is the correct foreign key
puts donkey.zoo_id #nil
# This is the (incorrect) attribute set by Zoo.animals.create
puts donkey.place_id # 1
donkey.save # Raises an error: "table animals has no column named place_id"
Note that Animal.new(:name => "donkey", :zoo =>
zoo)
appears to work correctly.
Comments and changes to this ticket
-
Dan Kubb (dkubb) July 2nd, 2009 @ 11:16 AM
- State changed from new to accepted
-
Dan Kubb (dkubb) July 2nd, 2009 @ 11:18 AM
- State changed from accepted to resolved
(from [f73f6a676adb7803cc8066ad4ae6828dbafe14f9]) Fixed relationship inheritance so inferred FK is based on base relationship
- Spec relationship inheritance behavior
- Added #inherited_by to 1:m, m:1 and m:m relationships for handling reinitializing a relationship in a subclass.
- Added ManyToMany::Relationship#invert
- Refactored Relationship comparison logic
[#921 state:resolved] http://github.com/datamapper/dm-core/commit/f73f6a676adb7803cc8066a...
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 »
People watching this ticket
Referenced by
-
921 In 0.10, new on associations with STI parent sets incorrect foreign key property, causing object to be unsaveable [#921 state:resolved] http://github.com/datamapper/dm-co...