0

For booleans I can use this in ruby and it works.

@listing=listing.draft? && listing.published?

But what if I have multiple queries which returns an array or something

Lets say drafts and published are two methods on the model which returns array of listings

so any handy method to get both like && and || in boolean?

If i do below code I can see that only the last query(after &&) gets saved always and the first one(before &&) gets overriden..

@listings=listing.drafts && listing.published

PS: I know I can get each seperately and push that to an array but as there are out of the box methods for booleans is it possible to do that for non boolean queries?

2
  • 1
    You can use listing.where(status: [:draft, :published]). If you are using enum then replace names(draft and published) with enum values. Commented Feb 21, 2017 at 2:44
  • @jaspreet21anand Thank you.. Commented Feb 21, 2017 at 2:53

1 Answer 1

1

You can use listing.where(status: [:draft, :published]). This will fire a IN query if using SQL database. If you are using enum then replace names(draft and published) with enum values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.