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

Instance Method Details

#foreign_key_mappingHash

Returns the conditions required to match the subject relationship

Returns:



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

Parameters:

  • record (Resource, Hash)

    The record containing the value to be matched

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


448
449
450
# File 'lib/dm-core/query/conditions/comparison.rb', line 448

def relationship?
  subject.kind_of?(Associations::Relationship)
end