我正在尝试做这种关系:
has_many :notifications, foreign_key: :notified_object_id, conditions: {notified_object_type: 'AppShare'}, dependent: :destroy
在此页面上找到:http://blog.meldium.com/home/2013/4/22/dont-spam-your-users-batch-notifications-in-rails
我已将其更改为:
has_many :notifications, -> { where( notified_object_type: 'Assigment') }, foreign_key: "notified_object_id", dependent: :destroy
由于rails 4的语法,但我得到了这个:
未初始化的常量Assigment :: Notification
有人可以帮助我吗?
由于
答案 0 :(得分:2)
对于那些看到类似错误的人,我必须将class_name: "Mailboxer::Notification"
添加到has_many
关系中。
has_many :notifications, -> { where( notified_object_type: 'Assignment') },
foreign_key: "notified_object_id", dependent: :destroy,
class_name: "Mailboxer::Notification"
答案 1 :(得分:0)
这可能只是你在“作业”上做的错误吗? (你已拼写过它' Assigment',没有N.)