Sha256: 7cf58632d4d500d7f4bbb49d08acb10c24363379f18cf2c2a375c66c06159f73

Contents?: true

Size: 698 Bytes

Versions: 2

Compression:

Stored size: 698 Bytes

Contents

# frozen_string_literal: true

module Phlexi
  module Form
    module Components
      class BelongsTo < Select
        protected

        delegate :association_reflection, to: :field

        def build_attributes
          super

          build_belongs_to_attributes
        end

        def build_belongs_to_attributes
          attributes.fetch(:input_param) do
            attributes[:input_param] = if association_reflection.respond_to?(:options) && association_reflection.options[:foreign_key]
              association_reflection.options[:foreign_key]
            else
              :"#{association_reflection.name}_id"
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phlexi-form-0.6.1 lib/phlexi/form/components/belongs_to.rb
phlexi-form-0.6.0 lib/phlexi/form/components/belongs_to.rb