나는 다음과 같은 모델을 가지고 : 당신이 볼 수 있듯이레일 3 : 다형성 조건 쿼리
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
모델에는 이벤트 문자열 속성이 있습니다.으로 정렬 된 모든 사용자 알림 이메일 알림 및 특정 이벤트 값을 가진 모든 반송 이메일 알림을 검색하려면 어떻게해야합니까? 이 (사용 squeel) 같은
뭔가 :
(Notification.joins{ notificatable(BounceEmailNotification) }.where('bounce_email_notifications.event' => 'error') + Notification.joins { notificatable(UserNotifierEmailNotification) }).sort_by { |n| n.created_at }
가 작동하지만 내가 알림을 주문 루비를 사용하지 않습니다. 내가 무엇을 할 수 있을지? 감사합니다