Class: JsonApiModel::Associations::BelongsTo
- Inherits:
-
Base
- Object
- Base
- JsonApiModel::Associations::BelongsTo
show all
- Includes:
- Flattable
- Defined in:
- lib/json_api_model/associations/belongs_to.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #opts
Instance Method Summary
collapse
Methods inherited from Base
#fetch, #initialize
Instance Method Details
#action ⇒ Object
6
7
8
|
# File 'lib/json_api_model/associations/belongs_to.rb', line 6
def action
:find
end
|
#key ⇒ Object
10
11
12
|
# File 'lib/json_api_model/associations/belongs_to.rb', line 10
def key
"#{name}_id"
end
|
#query(instance) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/json_api_model/associations/belongs_to.rb', line 14
def query( instance )
if instance.has_relationship_ids? name
{ id: instance.relationship_ids( name ) }
else
instance.send key
end
end
|