Skip to content

Instantly share code, notes, and snippets.

@thauanz
Last active September 24, 2015 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thauanz/ae2ab4ddfc7d8f749d1e to your computer and use it in GitHub Desktop.
Save thauanz/ae2ab4ddfc7d8f749d1e to your computer and use it in GitHub Desktop.
Blacklist
module Blacklist
extend ActiveSupport::Concern
module ClassMethods
def where_blacklist(query)
where(query)
end
end
def self.included(r)
r.extend ClassMethods
end
end
class Client < ActiveRecord::Base
belongs_to :club
end
class Club < ActiveRecord::Base
include Blacklist
has_many :clients
end
Club.where_blacklist("clients.id NOT IN (1,2,3,4)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment