JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Use `records` for joined resources

Open
#1,308 0 comments 4 reactions 1 assignee View on GitHub

@lgebhardt is already working on this.

Since Feb 10, 2020.

Type: Enhancement
Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.