Exclude active record set from another record set?

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

I tried this before with ugly code trying to remove id by adding them to the hash and excluding them from the request.

Should there be a clean way to remove a specific identifier or results from a recordset?

+6
source share
1 answer

You can do a negative where as follows:

 Post.where.not(author: author) 

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

+20
source

Source: https://habr.com/ru/post/953010/


All Articles