lib/sugarcrm/base.rb in sugarcrm-0.9.3 vs lib/sugarcrm/base.rb in sugarcrm-0.9.4

- old
+ new

@@ -150,26 +150,17 @@ def find_by_sql(options) query = query_from_options(options) SugarCRM.connection.get_entry_list(self._module.name, query, options) end - + def query_from_options(options) # If we dont have conditions, just return an empty query return "" unless options[:conditions] conditions = [] - options[:conditions].each_pair do |column, v| - v = [] << v unless v.class == Array - - v.each{|value| - # parse operator in cases where (e.g.) :attribute => '>= some_value', fallback to '=' operator as default - operator = value.to_s[/^([<>=]*)(.*)$/,1] - operator = '=' if operator.nil? || operator.strip == '' - - value = $2 # strip the operator from value passed to query - value = value.strip[/'?([^']*)'?/,1] - conditions << "#{table_name_for(column)}.#{column} #{operator} \'#{value}\'" - } + options[:conditions].each do |condition| + # Merge the result into the conditions array + conditions |= flatten_conditions_for(condition) end conditions.join(" AND ") end # Enables dynamic finders like <tt>find_by_user_name(user_name)</tt> and <tt>find_by_user_name_and_password(user_name, password)</tt> \ No newline at end of file