Skip to content

[RFC] Support for inheritance among resources #844

Closed
@maurei

Description

@maurei

Recently a PR was merged which introduces support for updating relationships of a resource when relationship types are abstract. It is supported by accepting for these relationship assignments members of types that are derived from this abstract relationship type. (see #696 and #833). It is said that this implementation allows for heterogeneous relationships because eg Article.Author can be assigned to either Student or Teacher.

Having such heterogeneity in relationships is in accordance with the way how JADNC currently deals with endpoints for abstract resources. Responses of these endpoints are currently heterogeneous too, i.e. the /people endpoint for the abstract Person resource will return entries of types students and teachers, not people.

Having heterogeneous responses from abstract endpoints was however never the result of a conscious design choice. A different approach could be having homogeneous responses where the type is just people, containing only the subset of attributes shared by all derived types. There currently is no consensus in the json:api community as to which approach is best (see json-api/json-api#862 and json-api/json-api#28).

Both approaches have their pros and cons: it mostly depends on the specific use case of the developer. Therefore, I believe deciding on whichever is best (or perhaps even allow for both through configurability) depends on input/use cases of the community. Hence this is a tracking issue for that purpose.

Note that the following features are known to be broken when dealing with resource inheritance (also see #846):

  1. /people?include=... for to one, to many and many to many relationships
  2. Filtering on nested scopes, since this relies on the previous
  3. people?fields=...
  4. Pagination and sorting on nested scopes

All of these are broken because they rely on the construction of a Select clause when building the queries. This fails because when creating a new expression as a part of such projection, the resource factory does not take into consideration model inheritance. Instead, it tries to create a new expression using the abstract type, which is not possible. A mechanism would have to be incorporated that takes into account, if present, the discriminator configuration when choosing the type for which to create a new expression. I am currently not sure if this is even possible without prematurely executing the query.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions