【发布时间】:2017-07-31 01:25:42
【问题描述】:
以下代码在 rails 4.2.7 上运行良好,但在 rails 5+ 上它会抛出 NameError initialized constant 'BonesReqPhoto'
模型 l2_requirement.rb
has_one :bones_req_photo, -> { where requireable_type: "BonesReqPhoto" },
class_name: "ReqPhoto", foreign_key: :requireable_id,
foreign_type: :requireable_type
has_one :bubbling_req_photo, -> { where requireable_type: "BubblingReqPhoto" },
class_name: "ReqPhoto", foreign_key: :requireable_id,
foreign_type: :requireable_type
模型 req_photo.rb
belongs_to :requireable, polymorphic: true
模型多次使用多态关联。 where 约束用于区分两者。
我使用这个答案来弄清楚如何为 rails 4 解决这个问题,但试图让它适用于 rails 5 却无济于事:imageable type is not setting for polymorphic associations
在 Rails 5 中执行此操作的正确方法是什么?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4