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:

  • (Hash)

471
472
473
474
475
476
# File 'lib/dm-core/query/conditions/comparison.rb', line 471

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)

458
459
460
461
462
463
464
# File 'lib/dm-core/query/conditions/comparison.rb', line 458

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)

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

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