Sha256: 4d604bd3b6efd674fa08e0a4ac4defedf28f648d3248c7489892f61138f0c369

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

module ActiveData
  module Model
    module Associations
      module Reflections
        class ReferencesMany < ReferenceReflection
          def self.build target, generated_methods, name, *args, &block
            reflection = super

            target.add_attribute(
              ActiveData::Model::Attributes::Reflections::ReferenceMany,
              reflection.reference_key, association: name)

            reflection
          end

          def collection?
            true
          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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_data-1.0.0 lib/active_data/model/associations/reflections/references_many.rb