Sha256: 7e795894588b548a0f5eb23923def1fe21b310fc4e208cb23b783461458e1286

Contents?: true

Size: 797 Bytes

Versions: 9

Compression:

Stored size: 797 Bytes

Contents

require 'active_data/model/attributes/reflections/reference_one'
require 'active_data/model/attributes/reference_one'

module ActiveData
  module Model
    module Associations
      module Reflections
        class ReferencesOne < ReferencesAny
          include Singular

          def self.build(target, generated_methods, name, *args, &block)
            reflection = super

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

            reflection
          end

          def reference_key
            @reference_key ||= options[:reference_key].presence.try(:to_sym) ||
              :"#{name}_#{primary_key}"
          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_one.rb
active_data-1.1.7 lib/active_data/model/associations/reflections/references_one.rb
active_data-1.1.6 lib/active_data/model/associations/reflections/references_one.rb
active_data-1.1.5 lib/active_data/model/associations/reflections/references_one.rb
active_data-1.1.4 lib/active_data/model/associations/reflections/references_one.rb
active_data-1.1.3 lib/active_data/model/associations/reflections/references_one.rb
active_data-1.1.2 lib/active_data/model/associations/reflections/references_one.rb
active_data-1.1.1 lib/active_data/model/associations/reflections/references_one.rb
active_data-1.1.0 lib/active_data/model/associations/reflections/references_one.rb