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

Exclude data from relationships (unless included) #357

Open
ahx opened this issue Dec 3, 2018 · 16 comments
Open

Exclude data from relationships (unless included) #357

ahx opened this issue Dec 3, 2018 · 16 comments

Comments

@ahx
Copy link

ahx commented Dec 3, 2018

This is re-opening #252, because AFAIK fast_jsonapi does not support this in the current version.

In our scenario it is a bit costly to fetch the ids of related resources. So not returning "data" for specific relations by default, but just "links" would great. The goal is to return something like this:

"attributes": {
  ...
},
"relationships": {
  "comments": {
    "links": {
      "related": "http://localhost/api/v1/users/1/comments"
    }
},

Returning a link (URL) to the related records is possible with fast_jsonapi, but excluding "data" is AFAIK not suppordet and not possible via with sparse fieldsets as mentioned in #252.

jsonapi-serializers does this via has_many :comments, include_data: true (false by default).

@sumeetattree
Copy link

@ahx How are you handling this at the moment?

@ahx
Copy link
Author

ahx commented Feb 14, 2019

@sumeetattree I am currently not using fast_jsonapi :/

@sumeetattree
Copy link

@ahx Ah, damn. I just came across this library and this looks amazing on paper. Trying to move away from active_model_serializers. What are you using at the moment?

I am trying to rewrite the serializers without touching the old ones. So the idea is to run ams and the new library side by side until it's all ported.

What would you recommend?

@ahx
Copy link
Author

ahx commented Feb 14, 2019

@sumeetattree
Copy link

Thank you. I'll take a look.

@dpikt
Copy link

dpikt commented May 16, 2019

It looks like this may have been addressed in v1.5 with the :lazy_load_data option: 85b41c4

Does this cover your use case @ahx?

@raldred
Copy link

raldred commented May 20, 2019

@dpikt This does work to remove the need to return all IDs even if the relationship is not included, however when including the the relationship, the relationships block remains empty.

EG. Here I have passed in include: [:packages]
The includes are return but the relationship block remains empty

"relationships": {
        "packages": {},
},
"included": [
    {
      "id": "1",
      "type": "packages",
      "attributes": {
        "title": "Unfurnished",
        "description": "I want it completely unfurnished, no extra fluff for me",
        "price_in_pence": 305000,
        "price_per_week_in_pence": 70400,
        "promo_text": "",
        "currency": "GBP"
      }
    }
]

I believe the spec requires the following, in addition to the "included" block
https://jsonapi.org/format/1.0/#document-compound-documents

"relationships": {
  "packages": {
      "data": [
          {
            "type": "packages",
            "id": "1"
          }
        ]
      }
  }
}

@dpikt
Copy link

dpikt commented May 20, 2019

Yeah I noticed that... I was considering opening a new issue for it but I suppose this issue could work as a stand-in. Are you working on a PR for that @raldred? If not I might spin one up.

@raldred
Copy link

raldred commented May 20, 2019

I am not, only just arrived here due to coming across the issue. I will have a look into it further, unless you've made a start @dpikt ?

@dpikt
Copy link

dpikt commented May 20, 2019

I'll take a stab at it this week!

@dpikt
Copy link

dpikt commented Jun 10, 2019

PR opened!

@okolomoets
Copy link

@dpikt Is there any updates according your PR above?

@dpikt
Copy link

dpikt commented Sep 3, 2019

As far as I know there hasn't been any action on the PR. The entire library seems to be in stasis at the moment (see #433), if things pick back up hopefully the PR will be included in that.

@kapilnarula
Copy link

Eagerly looking forward for this fix

@dpikt
Copy link

dpikt commented Oct 4, 2019

PR ported to community fork here: jsonapi-serializer/jsonapi-serializer#10

@dpikt
Copy link

dpikt commented Oct 8, 2019

Resolved on community fork.

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

No branches or pull requests

6 participants