#921 ✓resolved
Greg Campbell

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

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

Tags

Referenced by

Pages