Method: Graphiti::Util::Persistence#initialize

Defined in:
lib/graphiti/util/persistence.rb

#initialize(resource, meta, attributes, relationships, caller_model, foreign_key = nil) ⇒ Persistence

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Persistence.

Parameters:

  • resource (Resource)

    the resource instance

  • meta (Hash)

    see (Deserializer#meta)

  • attributes (Hash)

    see (Deserializer#attributes)

  • relationships (Hash)

    see (Deserializer#relationships)

  • caller_model (Model)

    The persisted parent object in the request graph

  • foreign_key (Symbol) (defaults to: nil)

    Attribute assigned by parent object in graph



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphiti/util/persistence.rb', line 10

def initialize(resource, meta, attributes, relationships, caller_model, foreign_key = nil)
  @resource = resource
  @meta = meta
  @attributes = attributes
  @relationships = relationships
  @caller_model = caller_model
  @foreign_key = foreign_key
  @adapter = @resource.adapter

  # Find the correct child resource for a given jsonapi type
  if (meta_type = @meta[:type].try(:to_sym))
    if @resource.type != meta_type && @resource.polymorphic?
      @resource = @resource.class.resource_for_type(meta_type).new
    end
  end
end