Sha256: 4069a99daf07e489b7350055ef79ef7dcfb9746f098fbe02ac79b8054a3decc0
Contents?: true
Size: 1.21 KB
Versions: 16
Compression:
Stored size: 1.21 KB
Contents
module RailsSettings module Extend extend ActiveSupport::Concern included do scope :with_settings, lambda { joins("JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND settings.thing_type = '#{base_class.name}')") .select("DISTINCT #{table_name}.*") } scope :with_settings_for, lambda { |var| joins("JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND settings.thing_type = '#{base_class.name}') AND settings.var = '#{var}'") } scope :without_settings, lambda { joins("LEFT JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND settings.thing_type = '#{base_class.name}')") .where('settings.id IS NULL') } scope :without_settings_for, lambda { |var| where('settings.id IS NULL') .joins("LEFT JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND settings.thing_type = '#{base_class.name}') AND settings.var = '#{var}'") } end def settings ScopedSettings.for_thing(self) end end end
Version data entries
16 entries across 16 versions & 1 rubygems