Sha256: 94032a87af8563bd0ffb8b9b2fb45b68e78d87edb7ec22ac733aa499929c6b24

Contents?: true

Size: 852 Bytes

Versions: 13

Compression:

Stored size: 852 Bytes

Contents

module Avo
  module Concerns
    module FindAssociationField
      # The supported association types are defined in the ASSOCIATIONS constant.
      unless defined?(ASSOCIATIONS)
        ASSOCIATIONS = ["belongs_to", "has_one", "has_many", "has_and_belongs_to_many", "array"]
      end

      # 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.
      def find_association_field(resource:, association:)
        resource.get_field_definitions.find do |field|
          (field.id == association.to_sym) && field.type.in?(ASSOCIATIONS)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
avo-3.17.3 lib/avo/concerns/find_association_field.rb
avo-3.17.5.tw4 lib/avo/concerns/find_association_field.rb
avo-3.17.4.tw4 lib/avo/concerns/find_association_field.rb
avo-3.17.3.tw4 lib/avo/concerns/find_association_field.rb
avo-3.17.2.tw4 lib/avo/concerns/find_association_field.rb
avo-3.17.2 lib/avo/concerns/find_association_field.rb
avo-3.17.1.tw4 lib/avo/concerns/find_association_field.rb
avo-3.17.1 lib/avo/concerns/find_association_field.rb
avo-3.17.0 lib/avo/concerns/find_association_field.rb
avo-3.16.6 lib/avo/concerns/find_association_field.rb
avo-3.16.5 lib/avo/concerns/find_association_field.rb
avo-3.16.4 lib/avo/concerns/find_association_field.rb
avo-3.16.3 lib/avo/concerns/find_association_field.rb