Sha256: 7da86926280fc01ceddf49b30d01a97c7878a209f2d791c206d93076ac747e73

Contents?: true

Size: 795 Bytes

Versions: 17

Compression:

Stored size: 795 Bytes

Contents

module PgSerializable
  module Nodes
    class Association < Base
      attr_reader :klass, :name, :trait, :type, :label

      def initialize(klass, name, type, label: nil, trait: :default)
        @name = name
        @klass = klass
        @type = type
        @label = label || name
        @trait = trait
      end

      def to_sql(outer_alias, aliaser)
        ["\'#{@label}\'", "(#{value(outer_alias, aliaser)})"].join(',')
      end

      def target
        @target ||= association.klass
      end

      def association
        @association ||= @klass.reflect_on_association(@name)
      end

      def foreign_key
        @foreign_key ||= association.join_foreign_key
      end

      def primary_key
        @primary_key ||= association.join_primary_key
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pg_serializable-3.1.0 lib/pg_serializable/nodes/association.rb
pg_serializable-3.0.2 lib/pg_serializable/nodes/association.rb
pg_serializable-3.0.1 lib/pg_serializable/nodes/association.rb
pg_serializable-3.0.0 lib/pg_serializable/nodes/association.rb
pg_serializable-2.1.1 lib/pg_serializable/nodes/association.rb
pg_serializable-2.1.0 lib/pg_serializable/nodes/association.rb
pg_serializable-2.0.0 lib/pg_serializable/nodes/association.rb
pg_serializable-1.4.0 lib/pg_serializable/nodes/association.rb
pg_serializable-1.3.2 lib/pg_serializable/nodes/association.rb
pg_serializable-1.3.1 lib/pg_serializable/nodes/association.rb
pg_serializable-1.3.0 lib/pg_serializable/nodes/association.rb
pg_serializable-1.2.2 lib/pg_serializable/nodes/association.rb
pg_serializable-1.2.1 lib/pg_serializable/nodes/association.rb
pg_serializable-1.2.0 lib/pg_serializable/nodes/association.rb
pg_serializable-1.1.0 lib/pg_serializable/nodes/association.rb
pg_serializable-1.0.1 lib/pg_serializable/nodes/association.rb
pg_serializable-1.0.0 lib/pg_serializable/nodes/association.rb