module KirguduBase module Common class PortalUser < ::KirguduBase::BaseModel include ::KirguduBase::Concerns::Models::UserId include ::KirguduBase::Concerns::Models::PortalId validates_presence_of :user_id, :portal_id validates_uniqueness_of :user_id, scope: :portal_id scope :by_status, lambda { |value| where { status_id == value } if value } scope :with_keyword, lambda { |value| if value value = value.gsub('%', '') like_value = "%#{value}%" where { (user.first_name.like like_value) | (user.last_name.like like_value) } end } def self.apply_filters_to_query(query, filters={}) filters ||= {} filters.merge!({ order: ["#{::KirguduBase::Common::Portal.table_name}.name asc", "#{::KirguduBase::Security::User.table_name}.last_name asc", "#{::KirguduBase::Security::User.table_name}.first_name asc"].join(", ") }) query = query.joins(:user).includes(:portal, :user) super(query, filters) end def name_for_breadcrumbs self.user_name end def to_s self.user_name end def as_json(options = { }) # just in case someone says as_json(nil) and bypasses # our default... super((options || { }).merge({ :methods => [:user_name, :portal_name] })) end end end end