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
#key, #name, #opts
Instance Method Summary
collapse
Methods inherited from Base
#fetch, #initialize
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
21
22
23
|
# File 'lib/json_api_model/associations/has.rb', line 21
def additional_options
[ :as, :through ]
end
|
#query(instance) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/json_api_model/associations/has.rb', line 9
def query( instance )
if instance.has_relationship_ids? name
{ id: instance.relationship_ids( name ) }
elsif through?
{ id: target_ids( instance ) }
elsif as?
{ "#{as}_id" => instance.id }
else
{ key => instance.id }
end
end
|