Skip to content

Commit a799ee0

Browse files
authored
Merge pull request #809 from gottfrois/patch-1
Get relationship id from the resource
2 parents b4f4881 + 248a825 commit a799ee0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/jsonapi/resource_serializer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,11 @@ def link_object(source, relationship, include_linkage = false)
427427
def foreign_key_value(source, relationship)
428428
related_resource_id = if source.preloaded_fragments.has_key?(format_key(relationship.name))
429429
source.preloaded_fragments[format_key(relationship.name)].values.first.try(:id)
430-
elsif source._model.respond_to?("#{relationship.name}_id")
430+
elsif source.respond_to?("#{relationship.name}_id")
431431
# If you have direct access to the underlying id, you don't have to load the relationship
432432
# which can save quite a lot of time when loading a lot of data.
433433
# This does not apply to e.g. has_one :through relationships.
434-
source._model.public_send("#{relationship.name}_id")
434+
source.public_send("#{relationship.name}_id")
435435
else
436436
source.public_send(relationship.name).try(:id)
437437
end

0 commit comments

Comments
 (0)