我有以下型号:
class Notification < ActiveRecord::Base
belongs_to :notificatable, polymorphic: true
end
class BounceEmailNotification < ActiveRecord::Bas
has_one :notification, :as => :notificatable, :dependent => :destroy
end
class UserNotifierEmailNotification < ActiveRecord::Base
has_one :notification, :as => :notificatable, :dependent => :destroy
end
如您所见,通知可以是“退回电子邮件通知”或“用户通知电子邮件通知”类型。该BounceEmailNotification
模型具有事件字符串属性。如果我想检索具有特定事件值的所有用户通知电子邮件通知和所有退回电子邮件通知,该created_at
怎么办?
像这样的东西(使用squeel):
(Notification.joins{ notificatable(BounceEmailNotification) }.where('bounce_email_notifications.event' => 'error') + Notification.joins { notificatable(UserNotifierEmailNotification) }).sort_by { |n| n.created_at }
会工作,但我不想使用 Ruby 来订购通知。我能做些什么?谢谢