Class: JsonApiModel::Associations::Has
- Inherits:
-
Base
- Object
- Base
- JsonApiModel::Associations::Has
show all
- Defined in:
- lib/json_api_model/associations/has.rb
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
Instance Method Details
#action ⇒ Object
5
6
7
|
# File 'lib/json_api_model/associations/has.rb', line 5
def action
:where
end
|
#additional_options ⇒ Object
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
|
#key ⇒ Object
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
|