Module: ActiveRecord::JSONB::Associations::Association

Defined in:
lib/activerecord/jsonb/associations/association.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#create_scopeObject

rubocop:disable Metrics/AbcSize



18
19
20
21
22
23
24
25
# File 'lib/activerecord/jsonb/associations/association.rb', line 18

def create_scope
  super.tap do |scope|
    next unless options.key?(:foreign_store)
    scope[options[:foreign_store].to_s] ||= {}
    scope[options[:foreign_store].to_s][reflection.foreign_key] =
      owner[reflection.active_record_primary_key]
  end
end

#creation_attributesObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/activerecord/jsonb/associations/association.rb', line 5

def creation_attributes
  return super unless reflection.options.key?(:foreign_store)

  attributes = {}
  jsonb_store = reflection.options[:foreign_store]
  attributes[jsonb_store] ||= {}
  attributes[jsonb_store][reflection.foreign_key] =
    owner[reflection.active_record_primary_key]

  attributes
end