Lets say I have this 3 scopes:
scope :assembly_reclamation, -> { where(status: 5) }
scope :customer_reclamation, -> { where(status: 9) }
scope :wrong_delivery, -> { where(status: 12) }
Now let's say that I want to make a scope that joins those 3 categories. I am doing it right now like this:
scope :returnable, -> { where(status: [5, 9, 12]) }
While this works, it has some disadvantages. if I were to change the conditions of one of the 3 categories, I would have to rework the scope that contains them all as well.
Something like this seems more DRY:
scope :returnable, -> { assembly_reclamation.or.customer_reclamation.or.wrong_delivery }
But this is not valid code.
Is there a way to code it in such a fashion?
UPDATE
I know I have used an example using categories and ids, but please do not make it about it. It is about merging scopes.
UPDATE 2
I have changed the name of the attributes from id
to status
, because everyone was concentrating on the issue of the id
, and that is not the point of the question