Class: Hanami::Model::Association Private

Inherits:
Object
  • Object
show all
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

Since:

  • 0.7.0

Class Method Summary collapse

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

Since:

  • 0.7.0



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

Since:

  • 0.7.0



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