Gaelle
Gaelle

Reputation: 599

Rails reverse scope

I have

 scope :delivered, where(:status => Status::DELIVERED)
 SELECT "orders".* FROM "orders" WHERE "orders"."status" IN ('Pending', 'Partially Prepared')

Now I want to add new scope to get all except delivered orders.

 scope :not_delivered, where(:status != Status::DELIVERED)
 SELECT "orders".* FROM "orders" WHERE ('t')

How to get a reverse scope?

Upvotes: 2

Views: 928

Answers (1)

ksol
ksol

Reputation: 12255

You have to use a string condition. scope :not_delivered, where('status NOT ?', Status::DELIVERED).

Not confident about the syntax, I don't do SQL often. But you should get the idea.

Upvotes: 2

Related Questions