aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-04-04 01:29:19 +0900
committerkennyj <kennyj@gmail.com>2012-04-12 23:28:31 +0900
commit1e417d5cd2a014909b5b9b7b34110e3d0f2803b7 (patch)
tree0f1b36e6d013144a9f054eadbd5822b2f80b9776 /activerecord/lib
parenteda65f391edc1a4ba21fc51f076a442034095826 (diff)
downloadrails-1e417d5cd2a014909b5b9b7b34110e3d0f2803b7.tar.gz
rails-1e417d5cd2a014909b5b9b7b34110e3d0f2803b7.tar.bz2
rails-1e417d5cd2a014909b5b9b7b34110e3d0f2803b7.zip
Some refactor for association.
* Remove unused association_class method. * Remove a unnecessary assignment. * Move @updated to BelongsToAssociation that only reference this instance variable. * Reset @stale_state at the reset method. I think this place is right place.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/association.rb8
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb5
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb2
3 files changed, 7 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 3c41a303d3..4e09a43f8e 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -25,10 +25,7 @@ module ActiveRecord
def initialize(owner, reflection)
reflection.check_validity!
- @target = nil
@owner, @reflection = owner, reflection
- @updated = false
- @stale_state = nil
reset
reset_scope
@@ -46,6 +43,7 @@ module ActiveRecord
def reset
@loaded = false
@target = nil
+ @stale_state = nil
end
# Reloads the \target and returns +self+ on success.
@@ -215,10 +213,6 @@ module ActiveRecord
def stale_state
end
- def association_class
- @reflection.klass
- end
-
def build_record(attributes, options)
reflection.build_association(attributes, options) do |record|
attributes = create_scope.except(*(record.changed - [reflection.foreign_key]))
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index 97f531d064..81c6e400d2 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -14,6 +14,11 @@ module ActiveRecord
self.target = record
end
+ def reset
+ super
+ @updated = false
+ end
+
def updated?
@updated
end
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index da4c311bce..14aa557b6c 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -71,7 +71,7 @@ module ActiveRecord
end
def reset
- @loaded = false
+ super
@target = []
end