Class: ROM::SQL::Association
- Inherits:
-
Object
- Object
- ROM::SQL::Association
- Extended by:
- ClassMacros
- Includes:
- Options
- Defined in:
- lib/rom/sql/association.rb,
lib/rom/sql/association/name.rb,
lib/rom/sql/association/one_to_one.rb,
lib/rom/sql/association/many_to_one.rb,
lib/rom/sql/association/one_to_many.rb,
lib/rom/sql/association/many_to_many.rb,
lib/rom/sql/association/one_to_one_through.rb
Overview
Abstract association class
Direct Known Subclasses
Defined Under Namespace
Classes: ManyToMany, ManyToOne, Name, OneToMany, OneToOne, OneToOneThrough
Instance Attribute Summary collapse
-
#as ⇒ Symbol
(also: #name)
readonly
An optional association alias name.
-
#relation ⇒ Symbol
readonly
An optional relation identifier for the target.
-
#result ⇒ Symbol
readonly
Either :one or :many.
- #source ⇒ Object readonly
- #target ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(source, target, options = EMPTY_HASH) ⇒ Association
constructor
private
A new instance of Association.
-
#qualify(name, attribute) ⇒ QualifiedAttribute
Returns a qualified attribute name for a given dataset.
Constructor Details
#initialize(source, target, options = EMPTY_HASH) ⇒ Association
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Association.
40 41 42 43 44 |
# File 'lib/rom/sql/association.rb', line 40 def initialize(source, target, = EMPTY_HASH) @source = Name[source] @target = Name[[:relation] || target, target, [:as] || target] super end |
Instance Attribute Details
#as ⇒ Symbol (readonly) Also known as: name
Returns an optional association alias name.
35 |
# File 'lib/rom/sql/association.rb', line 35 option :as, accepts: [Symbol], reader: true, default: -> assoc { assoc.target.to_sym } |
#relation ⇒ Symbol (readonly)
Returns an optional relation identifier for the target.
27 |
# File 'lib/rom/sql/association.rb', line 27 option :relation, accepts: [Symbol], reader: true |
#result ⇒ Symbol (readonly)
Returns either :one or :many.
31 |
# File 'lib/rom/sql/association.rb', line 31 option :result, accepts: [Symbol], reader: true, default: -> assoc { assoc.class.result } |
#source ⇒ Object (readonly)
19 20 21 |
# File 'lib/rom/sql/association.rb', line 19 def source @source end |
#target ⇒ Object (readonly)
23 24 25 |
# File 'lib/rom/sql/association.rb', line 23 def target @target end |
Instance Method Details
#qualify(name, attribute) ⇒ QualifiedAttribute
Returns a qualified attribute name for a given dataset
This is compatible with Sequel’s SQL generator and can be used in query DSL methods
57 58 59 |
# File 'lib/rom/sql/association.rb', line 57 def qualify(name, attribute) QualifiedAttribute[name.dataset, attribute] end |