Method: JSONAPI::Relationship#initialize

Defined in:
lib/jsonapi/relationship.rb

#initialize(name, options = {}) ⇒ Relationship

Returns a new instance of Relationship.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jsonapi/relationship.rb', line 12

def initialize(name, options = {})
  @name = name.to_s
  @options = options
  @acts_as_set = options.fetch(:acts_as_set, false) == true
  @foreign_key = options[:foreign_key] ? options[:foreign_key].to_sym : nil
  @parent_resource = options[:parent_resource]
  @relation_name = options.fetch(:relation_name, @name)
  @polymorphic = options.fetch(:polymorphic, false) == true
  @polymorphic_types = options[:polymorphic_types]
  if options[:polymorphic_relations]
    ActiveSupport::Deprecation.warn('Use polymorphic_types instead of polymorphic_relations')
    @polymorphic_types ||= options[:polymorphic_relations]
  end

  use_related_resource_records_for_joins_default = if options[:relation_name]
                                                     false
                                                   else
                                                     JSONAPI.configuration.use_related_resource_records_for_joins
                                                   end
  
  @use_related_resource_records_for_joins = options.fetch(:use_related_resource_records_for_joins,
                                                          use_related_resource_records_for_joins_default) == true

  @always_include_optional_linkage_data = options.fetch(:always_include_optional_linkage_data, false) == true
  @eager_load_on_include = options.fetch(:eager_load_on_include, false) == true
  @allow_include = options[:allow_include]
  @class_name = nil
  @inverse_relationship = nil

  @_routed = false
  @_warned_missing_route = false

  exclude_links(options.fetch(:exclude_links, JSONAPI.configuration.default_exclude_links))

  # Custom methods are reserved for future use
  @custom_methods = options.fetch(:custom_methods, {})
end