rosa-build/lib/modules/models/acts_like_member.rb

34 lines
881 B
Ruby

# -*- encoding : utf-8 -*-
module Modules
module Models
module ActsLikeMember
extend ActiveSupport::Concern
included do |klass|
scope :not_member_of, lambda { |item|
where("
#{klass.table_name}.id NOT IN (
SELECT relations.object_id
FROM relations
WHERE (
relations.object_type = '#{klass.to_s}'
AND relations.target_type = '#{item.class.to_s}'
AND relations.target_id = #{item.id}
)
)
")
}
scope :search_order, order("CHAR_LENGTH(uname) ASC")
scope :without, lambda {|a| where("#{klass.table_name}.id NOT IN (?)", a)}
scope :search, lambda {|q| where("#{klass.table_name}.uname ILIKE ?", "%#{q.strip}%")}
end
module ClassMethods
end
end
end
end