Class: Uchi::Field::HasMany::Show
- Inherits:
-
Base::Show
- Object
- ViewComponent::Base
- Base::Show
- Uchi::Field::HasMany::Show
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
Instance Method Details
#associated_records ⇒ Object
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_repository ⇒ Object
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
|