def match_in(others)
      # trivial case: self is in others
      return self if others.include?(self)
      # filter for the same type
      unless others.all? { |other| self.class === other } then
        others = others.filter { |other| self.class === other }
      end
      # match on primary, secondary or alternate key
      match_unique_object_with_attributes(others, self.class.primary_key_attributes) or
      match_unique_object_with_attributes(others, self.class.secondary_key_attributes) or
      match_unique_object_with_attributes(others, self.class.alternate_key_attributes)
    end
def match_in(others)
      # trivial case: self is in others
      return self if others.include?(self)
      # filter for the same type
      unless others.all? { |other| self.class === other } then
        others = others.filter { |other| self.class === other }
      end
      # match on primary, secondary or alternate key
      match_unique_object_with_attributes(others, self.class.primary_key_attributes) or
      match_unique_object_with_attributes(others, self.class.secondary_key_attributes) or
      match_unique_object_with_attributes(others, self.class.alternate_key_attributes)
    end
Matches this dependent domain object with the others on type and key attributes
 in the scope of a parent object.
 Returns the object in others which matches this domain object, or nil if none.

 The match attributes are, in order:
 * the primary key
 * the secondary key
 * the alternate key

 This domain object is matched against the others on the above attributes in succession
 until a unique match is found. The key attribute matches are strict, i.e. each
 key attribute value must be non-nil and match the other value.

 @param [<Resource>] the candidate domain object matches
 @return [Resource, nil] the matching domain object, or nil if no match