I am trying to combine two scopes or add some more to an existing scope.
scope :public_bids, -> {
where(status: [Status::ACCEPTED, Status::OUTBID, Statu
I haven't tried using or
in a scope, but you may be able to chain the scopes together using Rails 5's new or
method, like this:
scope :public_or_outbid, -> {
where(status: [Status::ACCEPTED, Status::OUTBID, Status::SOLD, Status::NO_SALE], bid_type: [BidType::MANUAL, BidType::AUTO, BidType::LIVE])\
.or(where(status: Status::OUTBID, bid_type: BidType::MAXBID))
}
(Note that this only works in Rails 5)
You certainly can chain the conditions together like this:
MyObj.public_bids.or(MyObj.outbid_maxbids)
See this answer for more detail: Rails 5: ActiveRecord OR query