【发布时间】:2017-04-28 09:49:53
【问题描述】:
我需要一些帮助来查询这里(Rails 5.1)。我有一个名为Verification (belongs_to :verifiable, polymorphic: true) 的多态关联对象。其他对象,如Comment,可以有verifications (has_many :verifications, as: :verifiable),最后一个(按id 排序)被认为是当前的。 Verification 有一个枚举属性 status。我需要检索具有特定user_id(当前用户之一)或当前(即最后一个)具有正确状态的验证对象(例如approved)的cmets。
所以,我正在尝试:
self.where(user_id: user.id).or(self.joins(:verifications).limit(1).where(verifications: { status: 'approved' }))
但是 Rails 给了我以下错误:
Relation passed to #or must be structurally compatible. Incompatible values: [:joins, :references, :limit]
我该怎么办?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5 ruby-on-rails-5.1