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


18
19
20
21
# File 'lib/hanami/model/association.rb', line 18

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

rubocop:disable Metrics/MethodLength

Since:

  • 0.7.0


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hanami/model/association.rb', line 28

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