Sha256: 6fd83e39b12a7cec665b149d9efe852fde07dfd2759a3cc148e1fd50862bc884

Contents?: true

Size: 869 Bytes

Versions: 14

Compression:

Stored size: 869 Bytes

Contents

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

14 entries across 14 versions & 1 rubygems

Version Path
rom-sql-3.1.0 lib/rom/sql/associations/self_ref.rb
rom-sql-3.0.1 lib/rom/sql/associations/self_ref.rb
rom-sql-3.0.0 lib/rom/sql/associations/self_ref.rb
rom-sql-2.5.0 lib/rom/sql/associations/self_ref.rb
rom-sql-2.4.0 lib/rom/sql/associations/self_ref.rb
rom-sql-2.3.0 lib/rom/sql/associations/self_ref.rb
rom-sql-2.2.1 lib/rom/sql/associations/self_ref.rb
rom-sql-2.2.0 lib/rom/sql/associations/self_ref.rb
rom-sql-2.1.0 lib/rom/sql/associations/self_ref.rb
rom-sql-2.0.0 lib/rom/sql/associations/self_ref.rb
rom-sql-2.0.0.rc1 lib/rom/sql/associations/self_ref.rb
rom-sql-2.0.0.beta3 lib/rom/sql/associations/self_ref.rb
rom-sql-2.0.0.beta2 lib/rom/sql/associations/self_ref.rb
rom-sql-2.0.0.beta1 lib/rom/sql/associations/self_ref.rb