Sha256: ca16054a55c92f886f355840280def3e86ed5eb3d98e5b55c3806bf16d3dba62

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

# encoding: UTF-8

require_relative '../metadata/column'

module GoodData
  module Model
    ##
    # Reference to another data set
    #
    class Reference < Column
      attr_accessor :reference, :schema_ref

      def initialize(column, schema)
        super column, schema
        # pp column
        @name = column[:name]
        @reference = column[:reference]
        @schema_ref = column[:dataset]
        @schema = schema
      end

      ##
      # Generates an identifier of the referencing attribute using the
      # schema name derived from schemaReference and column name derived
      # from the reference key.
      #
      def identifier
        @identifier ||= "#{ATTRIBUTE_PREFIX}.#{@schema_ref}.#{@reference}"
      end

      def key
        "#{@name}_id"
      end

      def label_column
        "#{LABEL_PREFIX}.#{@schema_ref}.#{@reference}"
      end

      def to_maql_create
        "ALTER ATTRIBUTE {#{identifier}} ADD KEYS {#{@schema.table}.#{key}};\n"
      end

      def to_maql_drop
        "ALTER ATTRIBUTE {#{identifier} DROP KEYS {#{@schema.table}.#{key}};\n"
      end

      def to_manifest_part(mode)
        {
          'populates' => [label_column],
          'mode' => mode,
          'columnName' => name,
          'referenceKey' => 1
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gooddata-0.6.4 lib/gooddata/models/columns/reference.rb
gooddata-0.6.3 lib/gooddata/models/columns/reference.rb
gooddata-0.6.2 lib/gooddata/models/columns/reference.rb