ポリモーフィック モデルで使用delegate
しhas_many
たりhas_one
関連付けたりすることは可能ですか? それはどのように機能しますか?
class Generic < ActiveRecord::Base
...
belongs_to :generable, polymorphic: true
delegate :file_url, to: :image, allow_nil: true
delegate :type_cat, to: :cat, allow_nil: true
end
class Image < ActiveRecord::Base
...
has_one :generic, as: generable, dependent: :destroy
end
class Cat < ActiveRecord::Base
...
has_one :generic, as: generable, dependent: :destroy
end