Module: Avo::Concerns::FindAssociationField
- Included in:
- BaseApplicationController, BaseComponent
- Defined in:
- lib/avo/concerns/find_association_field.rb
Constant Summary collapse
- ASSOCIATIONS =
["belongs_to", "has_one", "has_many", "has_and_belongs_to_many"]
Instance Method Summary collapse
-
#find_association_field(resource:, association:) ⇒ Object
This method is used to find an association field for a given resource.
Instance Method Details
#find_association_field(resource:, association:) ⇒ Object
This method is used to find an association field for a given resource. Ideally, the exact type of the association should be known in advance. However, there are cases where the type is unknown and the method will return the first matching association field based on the provided association name.
14 15 16 17 18 |
# File 'lib/avo/concerns/find_association_field.rb', line 14 def find_association_field(resource:, association:) resource.get_field_definitions.find do |field| (field.id == association.to_sym) && field.type.in?(ASSOCIATIONS) end end |