lib/sugarcrm/base.rb in sugarcrm-0.9.6 vs lib/sugarcrm/base.rb in sugarcrm-0.9.7
- old
+ new
@@ -39,16 +39,11 @@
case args.first
when :first
find_initial(options)
when :all
- results = find_every(options)
- if results
- Array.wrap(results)
- else
- []
- end
+ Array.wrap(find_every(options)).compact
else
find_from_ids(args, options)
end
end
@@ -156,11 +151,11 @@
find_by_sql(options)
end
def find_by_sql(options)
query = query_from_options(options)
- SugarCRM.connection.get_entry_list(self._module.name, query, options)
+ SugarCRM.connection.get_entry_list(self._module.name, query, options) || nil # return nil instead of false if no results are found
end
def query_from_options(options)
# If we dont have conditions, just return an empty query
return "" unless options[:conditions]
@@ -339,9 +334,21 @@
comparison_object.instance_of?(self.class) &&
id.present? &&
comparison_object.id == id
end
alias :eql? :==
+
+ def update_attribute(name, value)
+ self.send("#{name}=".to_sym, value)
+ self.save
+ end
+
+ def update_attributes(attributes)
+ attributes.each do |name, value|
+ self.send("#{name}=".to_sym, value)
+ end
+ self.save
+ end
# Delegates to id in order to allow two records of the same type and id to work with something like:
# [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]
def hash
id.hash
\ No newline at end of file