module DataMapper::Query::Conditions::RelationshipHandler
Included into comparisons which are capable of supporting Relationships.
Public Instance Methods
foreign_key_mapping()
click to toggle source
Returns the conditions required to match the subject relationship
@return [Hash]
@api semipublic
# File lib/dm-core/query/conditions/comparison.rb, line 470 def foreign_key_mapping relationship = subject.inverse relationship = relationship.links.first if relationship.respond_to?(:links) Query.target_conditions(value, relationship.source_key, relationship.target_key) end
matches?(record)
click to toggle source
Tests that the record value matches the comparison
@param [Resource, Hash] record
The record containing the value to be matched
@return [Boolean]
@api semipublic
Calls superclass method
# File lib/dm-core/query/conditions/comparison.rb, line 457 def matches?(record) if relationship? && expected.respond_to?(:query) match_relationship?(record) else super end end
relationship?()
click to toggle source
Returns whether this comparison subject is a Relationship
@return [Boolean]
@api semipublic
# File lib/dm-core/query/conditions/comparison.rb, line 445 def relationship? subject.kind_of?(Associations::Relationship) end
Private Instance Methods
dump()
click to toggle source
@api private
Calls superclass method
# File lib/dm-core/query/conditions/comparison.rb, line 500 def dump if relationship? dump_relationship(loaded_value) else super end end
dump_relationship(value)
click to toggle source
@api private
# File lib/dm-core/query/conditions/comparison.rb, line 509 def dump_relationship(value) value end
match_relationship?(record)
click to toggle source
@api private
# File lib/dm-core/query/conditions/comparison.rb, line 480 def match_relationship?(record) expected.query.conditions.matches?(record_value(record)) end
typecast(value)
click to toggle source
Typecasts each value in the inclusion set
@return [Array<Object>]
@see AbtractComparison#typecast
@api private
Calls superclass method
# File lib/dm-core/query/conditions/comparison.rb, line 491 def typecast(value) if relationship? typecast_relationship(value) else super end end