Skip to content

Use foreign_key option when getting foreign key value.#1001

Merged
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
dougo:use-foreign_key-in-foreign_key_value
Mar 21, 2017
Merged

Use foreign_key option when getting foreign key value.#1001
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
dougo:use-foreign_key-in-foreign_key_value

Conversation

@dougo
Copy link
Copy Markdown
Contributor

@dougo dougo commented Mar 14, 2017

I noticed that I was getting N+1 queries when using always_include_to_one_linkage_data. I tracked it down to the foreign_key_value method, which does try to use the foreign key without loading the associated object, but it was hardcoded to use foo_id rather than using the relationship's :foreign_key option if provided. Pretty straightforward fix.

I also added a unit test for this logic, because I couldn't find any obvious way to modify an existing test to cover this. Let me know if you have a better idea (or if you think it doesn't need to be tested).

@lgebhardt lgebhardt merged commit accafce into JSONAPI-Resources:master Mar 21, 2017
@lgebhardt
Copy link
Copy Markdown
Contributor

@dougo Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants