Permalink
Browse files

Cleanup the proxy rollback #492

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@457 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Jan 18, 2005
1 parent bce0e14 commit 3ebde40cecdaaccc93b211ebe9e8590adf678483
Showing with 6 additions and 14 deletions.
  1. +6 −14 activerecord/lib/active_record/associations.rb
@@ -289,8 +289,7 @@ def has_one(association_id, options = {})
module_eval do
after_save <<-EOF
association = instance_variable_get("@#{association_name}")
- loaded = instance_variable_get("@#{association_name}_loaded")
- if loaded and not association.nil?
+ unless association.nil?
association["#{association_class_primary_key_name}"] = id
association.save(true)
association.send(:construct_sql)
@@ -365,8 +364,7 @@ def belongs_to(association_id, options = {})
module_eval do
before_save <<-EOF
association = instance_variable_get("@#{association_name}")
- loaded = instance_variable_get("@#{association_name}_loaded")
- if loaded and not association.nil? and association.new_record?
+ if not association.nil? and association.new_record?
association.save(true)
self["#{association_class_primary_key_name}"] = association.id
association.send(:construct_sql)
@@ -516,41 +514,35 @@ def associate_identification(association_id, association_class_name, foreign_key
def association_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, association_proxy_class)
define_method(association_name) do |*params|
force_reload = params.first unless params.empty?
- loaded = instance_variable_get("@#{association_name}_loaded")
- if loaded and not force_reload
- association = instance_variable_get("@#{association_name}")
- else
+ association = instance_variable_get("@#{association_name}")
+ if association.nil? or force_reload
association = association_proxy_class.new(self,
association_name, association_class_name,
association_class_primary_key_name, options)
retval = association.reload
unless retval.nil?
instance_variable_set("@#{association_name}", association)
- instance_variable_set("@#{association_name}_loaded", true)
else
instance_variable_set("@#{association_name}", nil)
- instance_variable_set("@#{association_name}_loaded", nil)
return nil
end
end
association
end
define_method("#{association_name}=") do |new_value|
- loaded = instance_variable_get("@#{association_name}_loaded")
association = instance_variable_get("@#{association_name}")
- unless loaded and association
+ if association.nil?
association = association_proxy_class.new(self,
association_name, association_class_name,
association_class_primary_key_name, options)
end
association.replace(new_value)
unless new_value.nil?
instance_variable_set("@#{association_name}", association)
- instance_variable_set("@#{association_name}_loaded", true)
else
instance_variable_set("@#{association_name}", nil)
- instance_variable_set("@#{association_name}_loaded", nil)
+ return nil
end
association
end

0 comments on commit 3ebde40

Please sign in to comment.