Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use records for joined resources #1308

Open
2 of 7 tasks
lgebhardt opened this issue Feb 10, 2020 · 0 comments · May be fixed by #1307
Open
2 of 7 tasks

Use records for joined resources #1308

lgebhardt opened this issue Feb 10, 2020 · 0 comments · May be fixed by #1307
Assignees

Comments

@lgebhardt
Copy link
Member

This issue is a (choose one):

  • Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • I've searched for an existing issue.
  • I've asked my question on Gitter and have not received a satisfactory answer.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • The feature I'm asking for is compliant with the JSON:API spec.

Description

Current:

In version 0.9 and earlier JR relied on the Rails eager loading using the ActiveRecord includes. In a typical Rails app this feature works great, but we ran into a lot of edge cases and performance compromises when auto generating the queries JR needs for complex requests - especially ones with complex includes. In addition the complexity grew with caching.

With this approach we recommended that related resources be controlled using relation_name on the relationship. This relation was used in the includes and provides a way to control the related resources.

With version 0.10 the approach was changed and we no longer use rails eager loading. The relation_name on the relationship can still be used for relationship filtering.

There is also the option of using the apply_join callable on the relationship.

Both of the above options however require explicitly wiring up the appropriate code on each relationship.

Proposed change:

When joining related records in ActiveRelationResource.apply_join we have to opportunity to use ActiveRecord's merge method to apply the related resource's records logic. The implication of this is all accesses to a Resource will use the same records applied logic whether coming to the resource as the primary resource in a request, as an included resource, or through the related link of the parent resource.

I believe this one change should drastically simplify resource authentication and opens up some further opportunities to further simplify most resources.

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

Successfully merging a pull request may close this issue.

1 participant