Rails Polymorphic Association with multiple associations on the same model

后端 未结 10 1907
无人及你
无人及你 2020-11-28 03:01

My question is essentially the same as this one: Polymorphic Association with multiple associations on the same model

However, the proposed/accepted solution does no

10条回答
  •  醉酒成梦
    2020-11-28 03:40

    For mongoid use this solution

    Had tough times after discovering this issue but got cool solution that works

    Add to your Gemfile

    gem 'mongoid-multiple-polymorphic'

    And this works like a charm:

      class Resource
    
      has_one :icon, as: :assetable, class_name: 'Asset', dependent: :destroy, autosave: true
      has_one :preview, as: :assetable, class_name: 'Asset', dependent: :destroy, autosave: true
    
      end
    

提交回复
热议问题