4 ms·
This is a `negate` method in Arel (by Rails): class User < ActiveRecord::Base def self.negate(scope) where_values = scope.where_values
by izietto 12y ago
This is a `negate` method in Arel (by Rails):
class User < ActiveRecord::Base
def self.negate(scope)
where_values = scope.where_values
scope.except(:where).where where_values.reduce(:and).not
end
def self.suspended
where.not(confirmed: true).where(arel_table[:created_at].lt 2.weeks.ago)
end
end
unsuspended_users = User.negate User.suspended
Do this in SQL. Composability is the real boost, and you have composabiliy when you don't have to build a string in order to interact with the db.