Class: JsonApiResource::Associations::HasManyPrefetched
- Inherits:
-
Base
- Object
- Base
- JsonApiResource::Associations::HasManyPrefetched
show all
- Defined in:
- lib/json_api_resource/associations/has_many_prefetched.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, #post_process
Instance Method Details
#callable?(root_instance) ⇒ Boolean
16
17
18
|
# File 'lib/json_api_resource/associations/has_many_prefetched.rb', line 16
def callable?( root_instance )
root_instance.send(key).present?
end
|
#default_action ⇒ Object
4
5
6
|
# File 'lib/json_api_resource/associations/has_many_prefetched.rb', line 4
def default_action
:where
end
|
#nil_default ⇒ Object
20
21
22
|
# File 'lib/json_api_resource/associations/has_many_prefetched.rb', line 20
def nil_default
[]
end
|
#query(root_instance) ⇒ Object
12
13
14
|
# File 'lib/json_api_resource/associations/has_many_prefetched.rb', line 12
def query( root_instance )
{ id: root_instance.send(key) }.merge(opts)
end
|
#server_key ⇒ Object
8
9
10
|
# File 'lib/json_api_resource/associations/has_many_prefetched.rb', line 8
def server_key
@opts[:prefetched_ids]
end
|
#validate_options ⇒ Object
28
29
30
31
|
# File 'lib/json_api_resource/associations/has_many_prefetched.rb', line 28
def validate_options
raise_unless key == server_key, "#{root}.#{name} cannot specify both prefetched_ids and a foreign key"
super
end
|