Class: ROM::Associations::Abstract
- Inherits:
-
Object
- Object
- ROM::Associations::Abstract
- Defined in:
- core/lib/rom/associations/abstract.rb
Overview
Abstract association class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#definition ⇒ ROM::Associations::Definition
readonly
Association configuration object.
-
#relations ⇒ ROM::RelationRegistry
readonly
Relation registry.
-
#source ⇒ ROM::SQL::Relation
readonly
The source relation.
-
#target ⇒ ROM::SQL::Relation::Name
readonly
The target relation.
Class Method Summary collapse
-
.new(definition, relations) ⇒ Object
Create an association object.
Instance Method Summary collapse
-
#aliased? ⇒ Boolean
Return if an association has an alias.
-
#apply_view(schema, relation) ⇒ Relation
Applies custom view to the default association view.
-
#as ⇒ Symbol
Return association alias.
-
#combine_keys ⇒ Hash<Symbol=>Symbol>
Return combine keys hash.
-
#foreign_key ⇒ Symbol
Return association foreign key name.
-
#key ⇒ Symbol
Return the name of a key in tuples under which loaded association data are returned.
-
#name ⇒ Symbol
Return association canonical name.
-
#override? ⇒ Boolean
Return if a custom view should override default association view.
-
#result ⇒ Symbol
Return result type.
-
#view ⇒ Symbol
Return the name of a custom relation view that should be use to extend or override default association view.
Instance Attribute Details
#definition ⇒ ROM::Associations::Definition (readonly)
Returns Association configuration object.
23 |
# File 'core/lib/rom/associations/abstract.rb', line 23 param :definition |
#relations ⇒ ROM::RelationRegistry (readonly)
Returns Relation registry.
27 |
# File 'core/lib/rom/associations/abstract.rb', line 27 option :relations, reader: true |
#source ⇒ ROM::SQL::Relation (readonly)
Returns the source relation.
31 |
# File 'core/lib/rom/associations/abstract.rb', line 31 option :source, reader: true |
#target ⇒ ROM::SQL::Relation::Name (readonly)
Returns the target relation.
35 |
# File 'core/lib/rom/associations/abstract.rb', line 35 option :target, reader: true |
Class Method Details
.new(definition, relations) ⇒ Object
Create an association object
43 44 45 46 47 48 49 50 |
# File 'core/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 |
Instance Method Details
#aliased? ⇒ Boolean
Return if an association has an alias
57 58 59 |
# File 'core/lib/rom/associations/abstract.rb', line 57 def aliased? definition.aliased? end |
#apply_view(schema, relation) ⇒ Relation
Applies custom view to the default association view
132 133 134 135 |
# File 'core/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 ⇒ Symbol
Return association alias
66 67 68 |
# File 'core/lib/rom/associations/abstract.rb', line 66 def as definition.as end |
#combine_keys ⇒ Hash<Symbol=>Symbol>
Return combine keys hash
Combine keys are used for merging associated data together, typically these are the same as fk<=>pk mapping
145 146 147 |
# File 'core/lib/rom/associations/abstract.rb', line 145 def combine_keys definition.combine_keys || { source_key => target_key } end |
#foreign_key ⇒ Symbol
Return association foreign key name
94 95 96 |
# File 'core/lib/rom/associations/abstract.rb', line 94 def foreign_key definition.foreign_key end |
#key ⇒ Symbol
Return the name of a key in tuples under which loaded association data are returned
123 124 125 |
# File 'core/lib/rom/associations/abstract.rb', line 123 def key as || name end |
#name ⇒ Symbol
Return association canonical name
75 76 77 |
# File 'core/lib/rom/associations/abstract.rb', line 75 def name definition.name end |
#override? ⇒ Boolean
Return if a custom view should override default association view
114 115 116 |
# File 'core/lib/rom/associations/abstract.rb', line 114 def override? definition.override end |
#result ⇒ Symbol
Return result type
This can be either :one or :many
105 106 107 |
# File 'core/lib/rom/associations/abstract.rb', line 105 def result definition.result end |
#view ⇒ Symbol
Return the name of a custom relation view that should be use to extend or override default association view
85 86 87 |
# File 'core/lib/rom/associations/abstract.rb', line 85 def view definition.view end |