I’m very familiar with using hash arguments to ActiveRecord queries, such as:
SomeModel.where(association_id: something.id, status: ACTIVE_STATUSES).exists?
and similar. But what if you want to do a simple NOT EQUAL or != or <> type condition? My simple case is just to exclude the current object from the query.
The only way I can think of would be this:
SomeModel.where("id != ?", self.id).where(association_id: something.id,...)
But this seems not very rails-like.
Is there a simpler way, or a way to include the != in the hash conditions?
You can either drop to the Arel table.
There is a great (pro) Railscast on Arel.
http://railscasts.com/episodes/355-hacking-with-arel
You could also use the Squeel gem.
http://erniemiller.org/projects/squeel/
http://railscasts.com/episodes/354-squeel
In Squeel: