Reverse the relationship names in includes
See original GitHub issueI am not a 100% sure about this, but when all resource names are dasherized and pluralized, shouldn’t the included names be plural and dasherized too?
By included names I mean: http://jsonapi.org/format/#fetching-includes
Right now, I retrieve data like this: /api/v1/vehicle-checks?include=calendar_block
, which shows the mix in naming style: the ressource is dasherized and pluralized, the included ressource is not.
This request works, and ``?include=calendar-blocks` does not, which is obvious when looking at serializers.py lines 75 - 80.
So my question is, shouldn’t some reversing occur to match the naming style, similar to how the output is changed?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
how can I get all reverse relation names in the Django model?
It is possible using Model._meta.related_objects which contains a list of all related models. Example: for rel in Model.
Read more >Serializer relations - Django REST framework
To include a reverse relationship, you must explicitly add it to the fields list. For example: class AlbumSerializer(serializers.
Read more >Define a relationship
Reverse relationships occur where an entity has a relationship to another entity, ... Enter the textual form of the relationship name in the...
Read more >CROSSFILTER function - DAX | Microsoft Learn
Specifies the cross-filtering direction to be used in a calculation for a relationship that exists between two columns.
Read more >Relations (Reference) - Prisma
Many-to-many (also called m-n relations). The following Prisma schema includes every type of relation: one-to-one: User ↔ Profile; one- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a fairly old issue and there might be some confusion. So to clarify the specification states that the include query param are relationship field names and not resource names (see https://jsonapi.org/format/#fetching-includes).
So simply running the include name through the
utils.undo_format_field_name
will do it. There is already someunderscoring
of include names happening here but it does not take into consideration that includes maybe nested (e.g. include=author-bio.author-type)This issue is related to #990 Maybe fixing both issue in one PR might be considered if the unformatting could happen in the utility method utils.get_included_resources).
@schtibe @jerel I just found myself in your same situation 😃. However I have a question: should includes refer always to the
resource_name
of the resource you want to include? or should they refer to the field name you defined in the serializer?Let me explain with some dummy (incomplete) code:
Now If I did
GET /cars/1/?include=human-passengers
I’d expect the view to return thehuman-passengers
resource included in the response (but it won’t).At the moment, to get this I’d have to do
GET /cars/1/?include=passengers
, becausepassengers
matches the field name inCarSerializer
.Acording to: http://jsonapi.org/format/#document-resource-objects http://jsonapi.org/format/#fetching-includes
What you put in the includes should be the whatever the
type
key says. In this case, thetype
key for thePassenger
resource should behuman-passengers
(because DRF jsonapi allows you to explicitely setresource_name
).