Class: Hanami::Model::Association Private
- Inherits:
-
Object
- Object
- Hanami::Model::Association
- Defined in:
- lib/hanami/model/association.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Association factory
Class Method Summary collapse
-
.build(repository, target, subject) ⇒ Object
private
Instantiate an association.
-
.lookup(association) ⇒ Object
private
Translate ROM SQL associations into Hanami::Model associations.
Class Method Details
.build(repository, target, subject) ⇒ Object
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.
Instantiate an association
20 21 22 23 |
# File 'lib/hanami/model/association.rb', line 20 def self.build(repository, target, subject) lookup(repository.root.associations[target]) .new(repository, repository.root.name.to_sym, target, subject) end |
.lookup(association) ⇒ Object
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.
Translate ROM SQL associations into Hanami::Model associations
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hanami/model/association.rb', line 29 def self.lookup(association) case association when ROM::SQL::Association::ManyToMany Associations::ManyToMany when ROM::SQL::Association::OneToOne Associations::HasOne when ROM::SQL::Association::OneToMany Associations::HasMany when ROM::SQL::Association::ManyToOne Associations::BelongsTo else raise "Unsupported association: #{association}" end end |