class ROM::Associations::Abstract

Abstract association class

@api public

Public Class Methods

new(definition, relations) click to toggle source

Create an association object

@param [Definition] definition The association definition object @param [RelationRegistry] relations The relation registry

@api public

Calls superclass method
# File lib/rom/associations/abstract.rb, line 43
def self.new(definition, relations)
  super(
    definition,
    relations: relations,
    source: relations[definition.source.relation],
    target: relations[definition.target.relation]
  )
end

Public Instance Methods

aliased?() click to toggle source

Return if an association has an alias

@return [Boolean]

@api public

# File lib/rom/associations/abstract.rb, line 57
def aliased?
  definition.aliased?
end
apply_view(schema, relation) click to toggle source

Applies custom view to the default association view

@return [Relation]

@api protected

# File lib/rom/associations/abstract.rb, line 132
def apply_view(schema, relation)
  view_rel = relation.public_send(view)
  schema.merge(view_rel.schema).uniq(&:key).(view_rel)
end
as() click to toggle source

Return association alias

@return [Symbol]

@api public

# File lib/rom/associations/abstract.rb, line 66
def as
  definition.as
end
combine_keys() click to toggle source

Return combine keys hash

Combine keys are used for merging associated data together, typically these are the same as fk<=>pk mapping

@return [Hash<Symbol=>Symbol>]

@api public

# File lib/rom/associations/abstract.rb, line 145
def combine_keys
  definition.combine_keys || { source_key => target_key }
end
foreign_key() click to toggle source

Return association foreign key name

@return [Symbol]

@api public

# File lib/rom/associations/abstract.rb, line 94
def foreign_key
  definition.foreign_key
end
join_key_map() click to toggle source

Return names of source PKs and target FKs

@return [Array<Symbol>]

@api private

# File lib/rom/associations/abstract.rb, line 154
def join_key_map
  join_keys.to_a.flatten(1).map(&:key)
end
key() click to toggle source

Return the name of a key in tuples under which loaded association data are returned

@return [Symbol]

@api public

# File lib/rom/associations/abstract.rb, line 123
def key
  as || name
end
name() click to toggle source

Return association canonical name

@return [Symbol]

@api public

# File lib/rom/associations/abstract.rb, line 75
def name
  definition.name
end
node() click to toggle source

Return target relation configured as a combine node

@return [Relation]

@api private

# File lib/rom/associations/abstract.rb, line 163
def node
  target.with(
    name: target.name.as(key),
    meta: { keys: combine_keys, combine_type: result, combine_name: key }
  )
end
override?() click to toggle source

Return if a custom view should override default association view

@return [Boolean]

@api public

# File lib/rom/associations/abstract.rb, line 114
def override?
  definition.override
end
prepare(target) click to toggle source

Prepare association's target relation for composition

@return [Relation]

@api private

# File lib/rom/associations/abstract.rb, line 188
def prepare(target)
  if override?
    target.public_send(view)
  else
    call(target: target)
  end
end
result() click to toggle source

Return result type

This can be either :one or :many

@return [Symbol]

@api public

# File lib/rom/associations/abstract.rb, line 105
def result
  definition.result
end
self_ref?() click to toggle source

Return if this association's source relation is the same as the target

@return [Boolean]

@api private

# File lib/rom/associations/abstract.rb, line 201
def self_ref?
  source.name.dataset == target.name.dataset
end
view() click to toggle source

Return the name of a custom relation view that should be use to extend or override default association view

@return [Symbol]

@api public

# File lib/rom/associations/abstract.rb, line 85
def view
  definition.view
end
wrap() click to toggle source

Return target relation as a wrap node

@return [Relation]

@api private

# File lib/rom/associations/abstract.rb, line 175
def wrap
  target.with(
    name: target.name.as(key),
    schema: target.schema.wrap,
    meta: { wrap: true, combine_name: key }
  )
end