Class: JsonApiResource::Associations::HasOne
- Inherits:
-
Base
- Object
- Base
- JsonApiResource::Associations::HasOne
show all
- Defined in:
- lib/json_api_resource/associations/has_one.rb
Instance Attribute Summary
Attributes inherited from Base
#action, #key, #name, #root
Instance Method Summary
collapse
Methods inherited from Base
#default_nil, #initialize, #klass, #opts
Instance Method Details
#callable?(root_instance) ⇒ Boolean
21
22
23
|
# File 'lib/json_api_resource/associations/has_one.rb', line 21
def callable?( root_instance )
true
end
|
#default_action ⇒ Object
8
9
10
|
# File 'lib/json_api_resource/associations/has_one.rb', line 8
def default_action
:where
end
|
#post_process(value) ⇒ Object
4
5
6
|
# File 'lib/json_api_resource/associations/has_one.rb', line 4
def post_process( value )
Array(value).first
end
|
#query(root_instance) ⇒ Object
17
18
19
|
# File 'lib/json_api_resource/associations/has_one.rb', line 17
def query( root_instance )
{ key => root_instance.id }.merge(opts)
end
|
#server_key ⇒ Object
12
13
14
15
|
# File 'lib/json_api_resource/associations/has_one.rb', line 12
def server_key
class_name = self.root.to_s.demodulize.underscore
"#{class_name}_id"
end
|