Module: KMDB::HasProperties

Included in:
Event, User
Defined in:
lib/kmdb/concerns/has_properties.rb

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kmdb/concerns/has_properties.rb', line 13

def self.included(mod)
  mod.class_eval do
    has_many :properties, class_name: 'KMDB::Property'

    # scope :with_properties, lambda { |*props|
    #   direction = props.delete(:exclude_missing) ? 'INNER' : 'LEFT'
    #   prop_table = Property.table_name
    #   selects = ["`#{table_name}`.*"]
    #   joins = []
    #   props.each_with_index { |prop,k|
    #     temp_name = "#{prop_table}_#{k}"
    #     selects << "`#{temp_name}`.`value` AS `#{prop.split.join('_')}`"
    #     joins << sanitize_sql_array([%Q{
    #       #{direction} JOIN `properties` AS `#{temp_name}`
    #       ON `#{table_name}`.id = `#{temp_name}`.event_id 
    #       AND `#{temp_name}`.`key` = ?}, KMDB::Key.get(prop)])
    #   }
    #   { select: selects.join(', '), joins: joins.join("\n") }
    # }
  end
end