Sha256: 574b13c90d8b79e2191049602b1c38cecf035a920b24dcdfddb2e0848e194636

Contents?: true

Size: 900 Bytes

Versions: 12

Compression:

Stored size: 900 Bytes

Contents

# frozen_string_literal: true

module ROM
  module SQL
    module Associations
      module SelfRef
        def self.included(klass)
          super
          klass.memoize :join_keys, :source_table, :source_alias, :source_attr, :target_attr
        end

        # @api public
        def join_keys
          { source_attr => target_attr }
        end

        # @api public
        def source_attr
          source[source_key].qualified(source_alias)
        end

        # @api public
        def target_attr
          target[target_key].qualified
        end

        protected

        # @api private
        def source_table
          self_ref? ? Sequel.as(source.name.dataset, source_alias) : source.name.dataset
        end

        # @api private
        def source_alias
          self_ref? ? :"#{source.name.dataset.to_s[0]}_0" : source.name.dataset
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rom-sql-3.6.4 lib/rom/sql/associations/self_ref.rb
rom-sql-3.6.3 lib/rom/sql/associations/self_ref.rb
rom-sql-3.6.2 lib/rom/sql/associations/self_ref.rb
rom-sql-3.6.1 lib/rom/sql/associations/self_ref.rb
rom-sql-3.6.0 lib/rom/sql/associations/self_ref.rb
rom-sql-3.5.0 lib/rom/sql/associations/self_ref.rb
rom-sql-3.4.0 lib/rom/sql/associations/self_ref.rb
rom-sql-3.3.3 lib/rom/sql/associations/self_ref.rb
rom-sql-3.3.2 lib/rom/sql/associations/self_ref.rb
rom-sql-3.3.1 lib/rom/sql/associations/self_ref.rb
rom-sql-3.3.0 lib/rom/sql/associations/self_ref.rb
rom-sql-3.2.0 lib/rom/sql/associations/self_ref.rb