Skip to content
This repository
Browse code

Merge branch 'master' of github.com:portablemind/compass_agile_enterp…

…rise
  • Loading branch information...
commit 0bbe93d5696d1c93c97af2a764c8bf02ad1607b1 2 parents cd02a08 + 6c2a67a
Christopher Woodward cwoodward authored
10 erp_base_erp_svcs/app/models/party.rb
@@ -177,12 +177,16 @@ def get_contact_by_method(m)
177 177 end
178 178
179 179 def respond_to?(m)
180   - ((get_contact_by_method(m.to_s).nil? ? super : true)) rescue super
  180 + (super ? true : get_contact_by_method(m.to_s)) rescue super
181 181 end
182 182
183 183 def method_missing(m, *args, &block)
184   - value = get_contact_by_method(m.to_s)
185   - (value.nil?) ? super : (return value)
  184 + if self.respond_to?(m)
  185 + value = get_contact_by_method(m.to_s)
  186 + (value.nil?) ? super : (return value)
  187 + else
  188 + super
  189 + end
186 190 end
187 191
188 192 #************************************************************************************************
38 erp_tech_svcs/lib/erp_tech_svcs/extensions/active_record/has_relational_dynamic_attributes.rb
@@ -21,20 +21,34 @@ def has_relational_dynamic_attributes
21 21
22 22 module SingletonMethods
23 23 def find_by_dynamic_attribute(value, options={})
24   - arel_query = AttributeValue.where('attributed_record_type = ?', self.name)
  24 + arel_query = AttributeValue.select("DISTINCT id,attributed_record_id, attributed_record_type,
  25 + attribute_type_id, value")
  26 + .where('attributed_record_type = ?', self.name)
25 27 .where(AttributeValue.arel_table[:value].matches("%#{value}%"))
26 28
  29 + #if type_iids are based add or clauses for the types
27 30 or_clauses = nil
28 31 options[:type_iids].each do |type_iid|
29   - type = AttributeType.where('description = ? or internal_identifier = ?',type_iid,type_iid).first
  32 + type = AttributeType.where('description = ? or internal_identifier = ?', type_iid, type_iid).first
30 33 raise "Attribute Type '#{type_iid}' does not exist" if type.nil?
31   - or_clauses = or_clauses.nil? ? AttributeValue.arel_table[:attribute_type_id].eq(type.id) : or_clauses.or(AttributeValue.arel_table[:attribute_type_id].eq(type.id))
  34 + or_clauses = if or_clauses.nil?
  35 + AttributeValue.arel_table[:attribute_type_id].eq(type.id)
  36 + else
  37 + or_clauses.or(AttributeValue.arel_table[:attribute_type_id].eq(type.id))
  38 + end
32 39 end if options[:type_iids]
33   -
  40 +
34 41 arel_query = arel_query.where(or_clauses) if or_clauses
  42 +
  43 + #get total_count if we need to return it
  44 + total_count = arel_query.count('attribute_values.id') if options[:return_total_count]
  45 +
35 46 arel_query = arel_query.limit(options[:limit]) if options[:limit]
36 47 arel_query = arel_query.offset(options[:offset]) if options[:offset]
37   - arel_query.all.collect(&:attributed_record)
  48 + records = arel_query.all.collect(&:attributed_record)
  49 +
  50 + #return total_count if option passed
  51 + options[:return_total_count] ? (return records, total_count) : records
38 52 end
39 53 end
40 54
@@ -71,7 +85,7 @@ def get_dynamic_attribute_of_type(attribute_type_iid)
71 85 attribute_value = self.attribute_values.includes(:attribute_type).where('attribute_types.internal_identifier = ? or attribute_types.description = ?', attribute_type_iid.to_s, attribute_type_iid.to_s).first
72 86 attribute_value.nil? ? nil : attribute_value
73 87 end
74   -
  88 +
75 89 def assign_dynamic_attribute_on_save
76 90 #template method overridden in implementing class
77 91 end
@@ -83,7 +97,7 @@ def has_dynamic_attribute_of_type? (attribute_type_iid)
83 97 def destroy_dynamic_attribute_of_type (attribute_type_iid)
84 98 self.attribute_values.includes(:attribute_type).destroy_all("attribute_types.internal_identifier = #{attribute_type_iid.to_s} or attribute_types.description = #{attribute_type_iid.to_s}")
85 99 end
86   -
  100 +
87 101 def add_dynamic_attribute(value, type, data_type)
88 102 attribute_type = AttributeType.where('description = ? or internal_identifier = ?', type, type).first
89 103 attribute_type = AttributeType.create(:description => type, :data_type => data_type) unless attribute_type
@@ -97,8 +111,8 @@ def method_missing(m, *args, &block)
97 111 end
98 112
99 113 end
100   -
101   - end#HasRelationalDynamicAttributes
102   - end#ActiveRecord
103   - end#Extensions
104   -end#ErpTechSvcs
  114 +
  115 + end #HasRelationalDynamicAttributes
  116 + end #ActiveRecord
  117 + end #Extensions
  118 +end #ErpTechSvcs

0 comments on commit 0bbe93d

Please sign in to comment.
Something went wrong with that request. Please try again.