Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude active record set from another recordset?

Is there a way to exclude the results of recordset #1 from recordset #2 in Rails 3 or 4, Activerecord?

I have tried this before with ugly code trying to remove the id's by adding them to a hash and excluding them from the query.

Must be a clean way to remove certain id's or results from a recordset?

like image 878
Rubytastic Avatar asked Sep 02 '13 21:09

Rubytastic


1 Answers

You can perform a negative where like this:

Post.where.not(author: author)

Taken from here: http://guides.rubyonrails.org/active_record_querying.html#not-conditions

like image 98
Zach Taylor Avatar answered Oct 17 '22 21:10

Zach Taylor