datamapper/dm-core

:belongs_to and Discriminator do not mix

codytealet opened this issue · 1 comments

class Image
end

class Apple
end

class Orange
end

class AppleImage < Image
    belongs_to :apple, :required=>false
end

class OrangeImage < Orange
    belongs_to :orange, :required=>false
end

ai = AppleImage.new
a = Apple.first
ai.apple = a
raise "couldn't save apple image" unless ai.save
#=> Exception: "couldn't save apple image"

this makes table :image have :apple_id and :orange_id as columns, but won't let you save a sub-object because it won't allow you to save without either an :apple_id or :orange_id

Even if I reformat the given example (see below) this bug report doesn't make much sense. Can you give us code that is minimal and works? This doesn't even include DataMapper...

class Image
end
class Apple
end
class Orange
end

class AppleImage < Image
  belongs_to :apple, :required=>false
end
class OrangeImage < Orange
  belongs_to :orange, :required=>false
end

ai = AppleImage.new
a = Apple.first
ai.apple = a
raise "couldn't save apple image" unless ai.save