spring-projects / spring-projects/spring-data-rest

Add existence flag to relationships [DATAREST-1422]

Open
#1,781 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: enhancement
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Dario Tortola opened DATAREST-1422 and commented

As-is: lets say we have an entity A related x to one with an entity B, so that A has a B b field

A { private B b; }

When A is converted to a resource by Spring Data Rest, that result will include the link to b

{ links : { b : { href: "host:port/path/b" }}}

Now, the relationship b is optional, so accessing that url returns 404, so the developer needs to account for that possible error and they won't know if there is a resource until they try, incurring both in communication time and exception-based programming.

Desired: if Link could have a "boolean present" field, the developer would know without an additional request. It could be a "Boolean present" to allow for "yes; no; I-don't-know-you-try". If Link is not modifiable could be wrapped or if final this information could be in a similar object

{ links : { b : { href: "host:port/path/b" }}, linkPresence : { b : false }}

Considering that this is only for x-to-one relationships, they would incur in additional database cost only if the relationship is lazy-loaded (which could be transmitted with the Boolean present = null).

If lazy-loaded, there's possibly a way to check if it has been initialized or otherwise to fill present with true|false.

Of course, the same consideration should be used with projections, considering that @JsonIgnored relationships wouldn't need this flag, since they aren't sent, etc


No further details from DATAREST-1422

Contributor guide

Open the contributing guide

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.