django-rest-framework-json-api icon indicating copy to clipboard operation
django-rest-framework-json-api copied to clipboard

SerializerMethodResourceRelatedField does not include meta section in relationship response.

Open BillBrower opened this issue 6 years ago • 1 comments

SerializerMethodResourceRelatedField does not include a meta section in the relationship response like ResourceRelatedField does. This doesn't make sense, because SerializerMethodResourceRelatedField extends ResourceRelatedField and both seem to return every related record in the response (for the record I've only tried with a little over a thousand related records).

So for example if you had an ObjectA with a has many relationship with ObjectB:

    objectbs = SerializerMethodResourceRelatedField(
        source='get_objectbs',
        many=True,
        model=ObjectB,
        read_only=True
    )

    def get_objectbs(self, obj):
        return ObjectB.objects.filter(objecta=obj)

then your response would look like:

"relationships": {
  "objectb": {
   "data": [...]
  }
}

instead of:

"relationships": {
  "objectb": {
    "meta": {
      "count": 2
    },
   "data": [...]
  }
}

BillBrower avatar Feb 09 '19 22:02 BillBrower

Thanks for reporting. This seems to be inconsistent.

At a first glance: Source code where SerializerMethodResourceRelatedField doesn't seem to pass through as SerializerMethodResourceRelatedField doesn't resolve into ManyRelatedField

PR is welcome.

sliverc avatar Feb 11 '19 08:02 sliverc