如何让scope
使用多个.count
?
scope :level_5, -> { (self.accomplished.key.count > 4) && (self.accomplished.adventure.count > 2)
&& (self.accomplished.health.count > 2) && (self.accomplished.work.count > 2) }
我也试过了:
scope :level_5, -> { self.accomplished.key.count > 4, self.accomplished.adventure.count > 2,
self.accomplished.health.count > 2), (self.accomplished.work.count > 2) }
或
scope :level_5, -> { accomplished.where(key.count > 4, adventure.count > 2,
health.count > 2, work.count > 2) }
或
scope :level_5, -> { "user.accomplished.key.count > 4" && "user.accomplished.adventure.count > 2" &&
"user.accomplished.health.count > 2" && "user.accomplished.work.count > 2" }
它将用于条件,所以如果:level_5
然后触发X。