Class: JsonApiModel::Associations::Has

Inherits:
Base
  • Object
show all
Defined in:
lib/json_api_model/associations/has.rb

Direct Known Subclasses

HasMany, HasOne

Instance Attribute Summary

Attributes inherited from Base

#base_class, #name, #opts

Instance Method Summary collapse

Methods inherited from Base

#association_class, #fetch, #initialize, #json_relationship?, #process

Constructor Details

This class inherits a constructor from JsonApiModel::Associations::Base

Instance Method Details

#actionObject



5
6
7
# File 'lib/json_api_model/associations/has.rb', line 5

def action
  :where
end

#additional_optionsObject



9
10
11
# File 'lib/json_api_model/associations/has.rb', line 9

def additional_options
  [ :as, :through ]
end

#ids(instance) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/json_api_model/associations/has.rb', line 23

def ids( instance )
  if json_relationship?
    instance.relationship_ids( name )
  elsif through?
    target_ids( instance )
  else
    instance.id
  end
end

#keyObject



13
14
15
16
17
18
19
20
21
# File 'lib/json_api_model/associations/has.rb', line 13

def key
  if json_relationship? || through?
    :id
  elsif as?
    "#{as}_id"
  else
    idify( base_class )
  end
end

#query(instance) ⇒ Object



33
34
35
# File 'lib/json_api_model/associations/has.rb', line 33

def query( instance )
  { key => ids( instance ) }
end