lib/sugarcrm/attributes/attribute_methods.rb in sugarcrm-0.9.10 vs lib/sugarcrm/attributes/attribute_methods.rb in sugarcrm-0.9.11

- old
+ new

@@ -30,11 +30,16 @@ # fallback to '=' operator as default] operator = attribute_condition.to_s[/^([!<>=]*(LIKE|IS|NOT|\s)*)(.*)$/,1].strip! # Default to = if we can't resolve the condition. operator ||= '=' # Extract value from query - value = $3 + value = $3 + if [TrueClass, FalseClass].include? attribute_condition.class + # fix value for checkboxes: users can pass true/false as condition, should be converted to '1' or '0' respectively + value = (attribute_condition.class == TrueClass ? '1' : '0') + end + # TODO: Write a test for sending invalid attribute names. # strip single quotes value = value.strip[/'?([^']*)'?/,1] conditions << "#{table_name_for(attribute)}.#{attribute} #{operator} \'#{value}\'" end @@ -127,10 +132,10 @@ # sets the id if it's a new record def save_modified_attributes! # Complain if we aren't valid raise InvalidRecord, errors.to_a.join(", ") if !valid? # Send the save request - response = SugarCRM.connection.set_entry(self.class._module.name, serialize_modified_attributes) + response = self.class.session.connection.set_entry(self.class._module.name, serialize_modified_attributes) # Complain if we don't get a parseable response back raise RecordsaveFailed, "Failed to save record: #{self}. Response was not a Hash" unless response.is_a? Hash # Complain if we don't get a valid id back raise RecordSaveFailed, "Failed to save record: #{self}. Response did not contain a valid 'id'." if response["id"].nil? # Save the id to the record, if it's a new record \ No newline at end of file