Module: DataMapper::Query::Conditions::RelationshipHandler
- Included in:
- EqualToComparison, InclusionComparison
- Defined in:
- lib/dm-core/query/conditions/comparison.rb
Overview
Included into comparisons which are capable of supporting Relationships.
Instance Method Summary collapse
-
#foreign_key_mapping ⇒ Hash
Returns the conditions required to match the subject relationship.
-
#matches?(record) ⇒ Boolean
Tests that the record value matches the comparison.
-
#relationship? ⇒ Boolean
Returns whether this comparison subject is a Relationship.
Instance Method Details
#foreign_key_mapping ⇒ Hash
Returns the conditions required to match the subject relationship
473 474 475 476 477 478 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 473 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) ⇒ Boolean
Tests that the record value matches the comparison
460 461 462 463 464 465 466 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 460 def matches?(record) if relationship? && expected.respond_to?(:query) match_relationship?(record) else super end end |
#relationship? ⇒ Boolean
Returns whether this comparison subject is a Relationship
448 449 450 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 448 def relationship? subject.kind_of?(Associations::Relationship) end |