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

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

Instance Attribute Summary

Attributes inherited from Base::Component

#field, #record, #repository

Instance Method Summary collapse

Methods inherited from Base::Component

#initialize, #value

Constructor Details

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

Instance Method Details

#associated_recordsObject



61
62
63
64
65
# File 'app/components/uchi/field/has_many.rb', line 61

def associated_records
  records = field.value(record)

  associated_repository.find_all(scope: records)
end

#associated_repositoryObject

Raises:

  • (NameError)


67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/components/uchi/field/has_many.rb', line 67

def associated_repository
  raise NameError, "No association named #{field.name.inspect} found on #{record.class}" unless reflection

  associated_model = reflection.klass
  repository_class = Uchi::Repository.for_model(associated_model)
  unless repository_class
    raise \
      NameError,
      "No repository found for associated model #{associated_model}"
  end

  repository_class.new
end