Module: ActiveRecord::JSONB::ConnectionAdapters::ReferenceDefinition

Defined in:
lib/activerecord/jsonb/connection_adapters/reference_definition.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#add_to(table) ⇒ Object

rubocop:enable Metrics/ParameterLists



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/activerecord/jsonb/connection_adapters/reference_definition.rb', line 30

def add_to(table)
  return super unless store

  table.column(store, :jsonb, null: false, default: {})

  return unless index

  column_names.each do |column_name|
    table.index(
      "(#{store}->>'#{column_name}')",
      using: :hash,
      name: "index_#{table.name}_on_#{store}_#{column_name}"
    )
  end
end

#initialize(name, polymorphic: false, index: true, foreign_key: false, type: :bigint, store: false, **options) ⇒ Object

rubocop:disable Metrics/ParameterLists



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/activerecord/jsonb/connection_adapters/reference_definition.rb', line 8

def initialize(
  name,
  polymorphic: false,
  index: true,
  foreign_key: false,
  type: :bigint,
  store: false,
  **options
)
  @store = store

  super(
    name,
    polymorphic: polymorphic,
    index: index,
    foreign_key: foreign_key,
    type: type,
    **options
  )
end