class JSONAPI::Relationship::ToMany

Attributes

reflect[R]

Public Class Methods

new(name, options = {}) click to toggle source
Calls superclass method JSONAPI::Relationship::new
# File lib/jsonapi/relationship.rb, line 183
def initialize(name, options = {})
  super
  @class_name = options.fetch(:class_name, name.to_s.camelize.singularize)
  @foreign_key ||= "#{name.to_s.singularize}_ids".to_sym
  @reflect = options.fetch(:reflect, true) == true
  if parent_resource
    @inverse_relationship = options.fetch(:inverse_relationship, parent_resource._type.to_s.singularize.to_sym)
  end
end

Public Instance Methods

allow_include?(context = nil) click to toggle source
# File lib/jsonapi/relationship.rb, line 205
def allow_include?(context = nil)
  strategy = if @allow_include.nil?
               JSONAPI.configuration.default_allow_include_to_many
             else
               @allow_include
             end

  if !!strategy == strategy #check for boolean
    return strategy
  elsif strategy.is_a?(Symbol) || strategy.is_a?(String)
    parent_resource.send(strategy, context)
  else
    strategy.call(context)
  end
end
include_optional_linkage_data?() click to toggle source
# File lib/jsonapi/relationship.rb, line 199
def include_optional_linkage_data?
  # :nocov:
  @always_include_optional_linkage_data || JSONAPI::configuration.always_include_to_many_linkage_data
  # :nocov:
end
to_s() click to toggle source
# File lib/jsonapi/relationship.rb, line 193
def to_s
  # :nocov: useful for debugging
  "#{parent_resource}.#{name}(ToMany)"
  # :nocov:
end