Skip to content

Commit

Permalink
Merge pull request rails#5722 from kennyj/some_refactor_for_association
Browse files Browse the repository at this point in the history
Some refactor for association.
  • Loading branch information
jonleighton committed Apr 12, 2012
2 parents eda65f3 + 1e417d5 commit 65be11f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 1 addition & 7 deletions activerecord/lib/active_record/associations/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def replace(record)
self.target = record
end

def reset
super
@updated = false
end

def updated?
@updated
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def ids_writer(ids)
end

def reset
@loaded = false
super
@target = []
end

Expand Down

0 comments on commit 65be11f

Please sign in to comment.