lib/sugarcrm/base.rb in sugarcrm-0.9.7 vs lib/sugarcrm/base.rb in sugarcrm-0.9.8

- old
+ new

@@ -3,11 +3,11 @@ # Unset all of the instance methods we don't need. instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$|^define_method$|^class$|^nil.$|^methods$|^instance_of.$|^respond_to)/ } # This holds our connection cattr_accessor :connection, :instance_writer => false - + # Tracks if we have extended our class with attribute methods yet. class_attribute :attribute_methods_generated self.attribute_methods_generated = false class_attribute :association_methods_generated @@ -228,15 +228,11 @@ options = { :conditions => find_attributes } record = find(:first, options) if record.nil? - record = self.new do |r| - r.send(:attributes=, protected_attributes_for_create, true) unless protected_attributes_for_create.empty? - r.send(:attributes=, unprotected_attributes_for_create, false) unless unprotected_attributes_for_create.empty? - end - #{'yield(record) if block_given?'} + record = self.new(unprotected_attributes_for_create) #{'record.save' if instantiator == :create} record else record end @@ -248,11 +244,11 @@ super end end def all_attributes_exists?(attribute_names) - attribute_names.all? { |name| attributes_from_module_fields.include?(name) } + attribute_names.all? { |name| attributes_from_module.include?(name) } end def construct_attributes_from_arguments(attribute_names, arguments) attributes = {} attribute_names.each_with_index { |name, idx| attributes[name] = arguments[idx] } @@ -267,15 +263,14 @@ end end # Creates an instance of a Module Class, i.e. Account, User, Contact, etc. - def initialize(attributes={}) + def initialize(attributes={}, &block) @modified_attributes = {} merge_attributes(attributes.with_indifferent_access) clear_association_cache - @associations = self.class.associations_from_module_link_fields define_attribute_methods define_association_methods typecast_attributes self end @@ -306,12 +301,12 @@ end # Saves the current object, and any modified associations. # Raises an exceptions if save fails for any reason. def save! - save_modified_attributes - save_modified_associations + save_modified_attributes! + save_modified_associations! true end def delete return false if id.blank? @@ -369,8 +364,9 @@ include AttributeValidations include AttributeTypeCast include AttributeSerializers include AssociationMethods extend AssociationMethods::ClassMethods + include AssociationCache end end; end \ No newline at end of file