Sha256: 1e1b105b8d614b1323a32db793c50db19b59b9bad2b0fb69d4ba8699afcfb9e6

Contents?: true

Size: 954 Bytes

Versions: 4

Compression:

Stored size: 954 Bytes

Contents

require 'granite/form/model/attributes/reflections/reference_many'
require 'granite/form/model/attributes/reference_many'

module Granite
  module Form
    module Model
      module Associations
        module Reflections
          class ReferencesMany < ReferencesAny
            def self.build(target, generated_methods, name, *args, &block)
              reflection = super

              target.add_attribute(
                Granite::Form::Model::Attributes::Reflections::ReferenceMany,
                reflection.reference_key,
                type: reflection.persistence_adapter.primary_key_type,
                association: name
              )

              reflection
            end

            def reference_key
              @reference_key ||= options[:reference_key].presence.try(:to_sym) ||
                :"#{name.to_s.singularize}_#{primary_key.to_s.pluralize}"
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
granite-form-0.5.0 lib/granite/form/model/associations/reflections/references_many.rb
granite-form-0.4.0 lib/granite/form/model/associations/reflections/references_many.rb
granite-form-0.3.0 lib/granite/form/model/associations/reflections/references_many.rb
granite-form-0.2.0 lib/granite/form/model/associations/reflections/references_many.rb