Class: Uchi::Field::HasMany::Show

Inherits:
Base::Show
  • Object
show all
Defined in:
app/components/uchi/field/has_many.rb

Instance Attribute Summary

Attributes inherited from Base::Show

#field, #record, #repository

Instance Method Summary collapse

Methods inherited from Base::Show

#initialize

Constructor Details

This class inherits a constructor from Uchi::Field::Base::Show

Instance Method Details

#associated_recordsObject



15
16
17
18
19
# File 'app/components/uchi/field/has_many.rb', line 15

def associated_records
  records = field.value(record)

  associated_repository.find_all(scope: records)
end

#associated_repositoryObject

Raises:

  • (NameError)


21
22
23
24
25
26
27
28
# File 'app/components/uchi/field/has_many.rb', line 21

def associated_repository
  reflection = record.class.reflect_on_association(field.name)
  model = reflection.klass
  repository_class = Uchi::Repository.for_model(model)
  raise NameError, "No repository found for associated model #{model}" unless repository_class

  repository_class.new
end