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



16
17
18
19
# File 'lib/hanami/model/association.rb', line 16

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



25
26
27
28
29
30
31
32
33
34
# File 'lib/hanami/model/association.rb', line 25

def self.lookup(association)
  case association
  when ROM::SQL::Association::OneToMany
    Associations::HasMany
  when ROM::SQL::Association::ManyToOne
    Associations::BelongsTo
  else
    raise "Unsupported association: #{association}"
  end
end