Skip to content

Commit

Permalink
Only fetch the old associates once
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wood committed Jul 7, 2011
1 parent 6258e00 commit db57267
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/tenacity/associations/has_many.rb
Expand Up @@ -95,16 +95,15 @@ def _t_save_associates(record, association)
# be fetched here, before we clear them out in the database.
old_associates.first

_t_clear_old_associations(record, association)
_t_clear_old_associations(record, association, old_associates)

associates = (record.instance_variable_get(record._t_ivar_name(association))) || []
establish_relationship_in_target_objects(record, association, associates)
destroy_orphaned_associates(association, old_associates, associates)
end

def _t_clear_old_associations(record, association)
def _t_clear_old_associations(record, association, old_associates)
property_name = association.foreign_key(record.class)
old_associates = get_current_associates(record, association)
old_associates.each do |old_associate|
old_associate.send("#{property_name}=", nil)
save_associate(old_associate)
Expand Down

0 comments on commit db57267

Please sign in to comment.