class ROM::Associations::Abstract
Abstract
association class
@api public
Public Class Methods
Create an association object
@param [Definition] definition The association definition object @param [RelationRegistry] relations The relation registry
@api public
# 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
Return if an association has an alias
@return [Boolean]
@api public
# File lib/rom/associations/abstract.rb, line 57 def aliased? definition.aliased? end
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
Return association alias
@return [Symbol]
@api public
# File lib/rom/associations/abstract.rb, line 66 def as definition.as end
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
Return association foreign key name
@return [Symbol]
@api public
# File lib/rom/associations/abstract.rb, line 94 def foreign_key definition.foreign_key end
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
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
Return association canonical name
@return [Symbol]
@api public
# File lib/rom/associations/abstract.rb, line 75 def name definition.name end
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
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 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
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
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
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
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