Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 1e417d5cd2a014909b5b9b7b34110e3d0f2803b7 1 parent eda65f3
@kennyj kennyj authored
View
8 activerecord/lib/active_record/associations/association.rb
@@ -25,10 +25,7 @@ class Association #:nodoc:
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 @@ def aliased_table_name
def reset
@loaded = false
@target = nil
+ @stale_state = nil
end
# Reloads the \target and returns +self+ on success.
@@ -215,10 +213,6 @@ def invertible_for?(record)
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]))
View
5 activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -14,6 +14,11 @@ def replace(record)
self.target = record
end
+ def reset
+ super
+ @updated = false
+ end
+
def updated?
@updated
end
View
2  activerecord/lib/active_record/associations/collection_association.rb
@@ -71,7 +71,7 @@ def ids_writer(ids)
end
def reset
- @loaded = false
+ super
@target = []
end
Please sign in to comment.
Something went wrong with that request. Please try again.