Module: ActiveType::RecordExtension::Inheritance

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_type/record_extension/inheritance.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.add_foreign_key_option(extended_record_base_class, scope = nil, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_type/record_extension/inheritance.rb', line 13

def self.add_foreign_key_option(extended_record_base_class, scope = nil, options = {})
  if scope.is_a?(Hash)
    options = scope
    scope = nil
  end
  unless options[:foreign_key] || options[:as]
    options = options.merge(foreign_key: extended_record_base_class.name.foreign_key)
  end
  if ActiveRecord::VERSION::MAJOR > 3
    [options, scope]
  else
    [options]
  end
end