0

I have my own rails app and I need to specify what I want to get from DB (pg). Ordinary, we do it like that: @posts = Post.all and I will get all the post in my Post Table.

In Post Table I have a categories, as a boolean: (photo, video, etc.) and when I want to select only posts witch response to photo category, we do it like that: @posts = Post.where(photo: true)

But what I need, is to select all posts without, for example, video. It have to look something like that: @posts = Post.all.without(video:true). How to make it happen?

UPDATED

And is there any possibility to block several values? I mean something like that Post.where.not(id: 1 && 2). I really don't know how it must look like. What i need - is to select all Posts without posts with ID 1 and 2.

3 Answers 3

5

Try

@posts = Post.where.not(video: true)
Sign up to request clarification or add additional context in comments.

Comments

1

you can use .not, for example

@posts = Post.where.not(video:true)

1 Comment

or @posts = Post.where(video: false)
1

You can pass an array of values: Post.where.not(id: [1, 2])

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.