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
470 471 472 473 474 475 |
# 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) ⇒ Boolean
Tests that the record value matches the comparison
457 458 459 460 461 462 463 |
# 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? ⇒ Boolean
Returns whether this comparison subject is a Relationship
445 446 447 |
# File 'lib/dm-core/query/conditions/comparison.rb', line 445 def relationship? subject.kind_of?(Associations::Relationship) end |