Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
prevent duplicates ids in the parent lookup and make more consistent …
Browse files Browse the repository at this point in the history
…with get_children
  • Loading branch information
Wesley Beary committed Jul 14, 2008
1 parent e5bc973 commit 74dc532
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/dm-core/associations/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ def get_children(parent, options = {}, finder = :all, *args)

# @api private
def get_parent(child, parent = nil)
bind_values = child_key.get(child)
child_value = bind_values.dup
child_value = child_key.get(child)
return nil unless child_value.nitems == child_value.size

with_repository(parent || parent_model) do
Expand All @@ -136,7 +135,7 @@ def get_parent(child, parent = nil)

children = child_identity_map.values

bind_values |= children.map { |c| child_key.get(c) }
bind_values = *children.map { |c| child_key.get(c) }.uniq
query_values = bind_values.reject { |k| parent_identity_map[[k]] }

bind_values = query_values unless query_values.empty?
Expand Down

0 comments on commit 74dc532

Please sign in to comment.