lib/sugarcrm/base.rb in sugarcrm-0.9.0 vs lib/sugarcrm/base.rb in sugarcrm-0.9.1
- old
+ new
@@ -30,11 +30,11 @@
:register_modules => true,
}.merge(opts)
@debug = options[:debug]
@@connection = SugarCRM::Connection.new(url, user, pass, options)
end
-
+
def find(*args)
options = args.extract_options!
validate_find_options(options)
case args.first
@@ -197,27 +197,10 @@
attribute_names = match.attribute_names
super unless all_attributes_exists?(attribute_names)
if match.finder?
finder = match.finder
bang = match.bang?
- # def self.find_by_login_and_activated(*args)
- # options = args.extract_options!
- # attributes = construct_attributes_from_arguments(
- # [:login,:activated],
- # args
- # )
- # finder_options = { :conditions => attributes }
- # validate_find_options(options)
- #
- # if options[:conditions]
- # with_scope(:find => finder_options) do
- # find(:first, options)
- # end
- # else
- # find(:first, options.merge(finder_options))
- # end
- # end
self.class_eval <<-EOS, __FILE__, __LINE__ + 1
def self.#{method_id}(*args)
options = args.extract_options!
attributes = construct_attributes_from_arguments(
[:#{attribute_names.join(',:')}],
@@ -237,35 +220,10 @@
end
EOS
send(method_id, *arguments)
elsif match.instantiator?
instantiator = match.instantiator
- # def self.find_or_create_by_user_id(*args)
- # guard_protected_attributes = false
- #
- # if args[0].is_a?(Hash)
- # guard_protected_attributes = true
- # attributes = args[0].with_indifferent_access
- # find_attributes = attributes.slice(*[:user_id])
- # else
- # find_attributes = attributes = construct_attributes_from_arguments([:user_id], args)
- # end
- #
- # options = { :conditions => find_attributes }
- # set_readonly_option!(options)
- #
- # record = find(:first, options)
- #
- # if record.nil?
- # record = self.new { |r| r.send(:attributes=, attributes, guard_protected_attributes) }
- # yield(record) if block_given?
- # record.save
- # record
- # else
- # record
- # end
- # end
self.class_eval <<-EOS, __FILE__, __LINE__ + 1
def self.#{method_id}(*args)
attributes = [:#{attribute_names.join(',:')}]
protected_attributes_for_create, unprotected_attributes_for_create = {}, {}
args.each_with_index do |arg, i|
@@ -320,14 +278,10 @@
end
end
# Creates an instance of a Module Class, i.e. Account, User, Contact, etc.
- # This call depends upon SugarCRM.modules having actual data in it. If you
- # are using Base.establish_connection, you should be fine. But if you are
- # using the Connection class by itself, you may need to prime the pump with
- # a call to Module.register_all
def initialize(attributes={})
@modified_attributes = {}
merge_attributes(attributes.with_indifferent_access)
clear_association_cache
@associations = self.class.associations_from_module_link_fields
@@ -360,12 +314,12 @@
return false
end
true
end
- # Saves the current object, checks that required fields are present.
- # raises an exception if a save fails
+ # 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
true
end
@@ -398,11 +352,9 @@
# [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]
def hash
id.hash
end
-
- # Wrapper around class attribute
def attribute_methods_generated?
self.class.attribute_methods_generated
end
def association_methods_generated?
\ No newline at end of file