Рассмотрим следующее:
class Picture
include Mongoid::Document
field :data, :type => String
end
class Cat
include Mongoid::Document
has_one :picture, :autosave => true
field :name, :type => String
end
class Dog
include Mongoid::Document
has_one :picture, :autosave => true
field :name, :type => String
end
Теперь возможно ли сделать следующее:
dog = Dog.new
dog.picture = Picture.new
dog.save!
Без необходимости редактировать класс Picture для следующего:
class Picture
include Mongoid::Document
belongs_to :cat
belongs_to :dog
field :data, :type => String
end
Мне не нужны картинки, чтобы знать о Dog
или Cat
. Это возможно?