Sha256: a19e69f38aaf47a009dd83074cbbe26d28b5fd0c8703fe1d8e26a22d25cd4d80

Contents?: true

Size: 421 Bytes

Versions: 15

Compression:

Stored size: 421 Bytes

Contents

module Superstore
  module Associations
    class HasOne < Association
      def reader
        unless loaded?
          self.target = load_target
        end

        target
      end

      def writer(record)
        self.target = record
      end

      private

        def load_target
          association_class.where(reflection.foreign_key => owner.try(reflection.primary_key)).first
        end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
superstore-3.0.0 lib/superstore/associations/has_one.rb
superstore-2.5.0 lib/superstore/associations/has_one.rb
superstore-2.4.4 lib/superstore/associations/has_one.rb
superstore-2.4.3 lib/superstore/associations/has_one.rb
superstore-2.4.2 lib/superstore/associations/has_one.rb
superstore-2.4.1 lib/superstore/associations/has_one.rb
superstore-2.4.0 lib/superstore/associations/has_one.rb
superstore-2.3.0 lib/superstore/associations/has_one.rb
superstore-2.2.0 lib/superstore/associations/has_one.rb
superstore-2.1.3 lib/superstore/associations/has_one.rb
superstore-2.1.2 lib/superstore/associations/has_one.rb
superstore-2.1.1 lib/superstore/associations/has_one.rb
superstore-2.1.0 lib/superstore/associations/has_one.rb
superstore-2.0.1 lib/superstore/associations/has_one.rb
superstore-2.0.0 lib/superstore/associations/has_one.rb