Sha256: c22fe7a351a5efb5799c716f4d04cd7f0d434722e89e52c4c356919197705069

Contents?: true

Size: 805 Bytes

Versions: 9

Compression:

Stored size: 805 Bytes

Contents

require 'active_data/model/attributes/reflections/reference_many'
require 'active_data/model/attributes/reference_many'

module ActiveData
  module Model
    module Associations
      module Reflections
        class ReferencesMany < ReferencesAny
          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 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

9 entries across 9 versions & 1 rubygems

Version Path
active_data-1.2.0 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.7 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.6 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.5 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.4 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.3 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.2 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.1 lib/active_data/model/associations/reflections/references_many.rb
active_data-1.1.0 lib/active_data/model/associations/reflections/references_many.rb