0

How can I get this scope to work with multiple .count?

scope :level_5, -> { (self.accomplished.key.count > 4) && (self.accomplished.adventure.count > 2)
&& (self.accomplished.health.count > 2) && (self.accomplished.work.count > 2) }

I've also tried:

scope :level_5, -> { self.accomplished.key.count > 4, self.accomplished.adventure.count > 2,
self.accomplished.health.count > 2), (self.accomplished.work.count > 2) }

or

scope :level_5, -> { accomplished.where(key.count > 4, adventure.count > 2,
health.count > 2, work.count > 2) }

or

scope :level_5, -> { "user.accomplished.key.count > 4" && "user.accomplished.adventure.count > 2" &&
"user.accomplished.health.count > 2" && "user.accomplished.work.count > 2" }

It will be used for conditionals so if :level_5 then trigger X.

AnthonyGalli.com
  • 2,796
  • 5
  • 31
  • 80
  • http://stackoverflow.com/questions/14623668/how-to-have-multiple-conditions-in-a-named-scope – Alireza Bashiri Nov 13 '16 at 10:09
  • 3
    Scope are used to construct database queries. I am not sure if all this values exist in the database or need to be calculated. Therefore: What is `accomplished`? Another scope, how is it defined? What are `key`, `health` and `work`? Columns in the database? It might help if you show how your database looks like, some example records and the expected result. – spickermann Nov 13 '16 at 10:11

0 Answers0