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)


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

Parameters:

  • record (Resource, Hash)

    The record containing the value to be matched

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

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