yahoo / elide

Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.

Home Page:https://elide.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inverse relationship hooks not triggering for polymorphic types

bladedancer opened this issue · comments

Expected Behavior

When deleting an entity in the many side of a oneToMany it triggers an update on the one side due to the relationship being updated. This can be used to trigger lifecycle hooks.

However in a polymorphic case (https://elide.io/pages/guide/v7/02-data-model.html#inheritance) when you delete the many side of the relationship the hooks don't trigger.

Current Behavior

The problem is due to how the relation inverse is performed.
https://github.com/yahoo/elide/blob/master/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityDictionary.java#L732

It's doing getParameterizedType(inverseType, inverseRelationName).equals(clsBinding.entityClass)
The problem is getParameterizedType is returning the base class, clsBinding.entityClass is the derived type...so equals is false.

Possible Solution

Moving from equals to isAssignableFrom seems to be a feasible solution.

Steps to Reproduce (for bugs)

I'll attach a pull request with updated unit tests.

Context

The lifecyclehooks are not firing on the one side of the relationship because the inverse relationship is returning an empty string.

Your Environment

  • Elide version used: 7.0.2
  • Environment name and version (Java 1.8.0_152): openjdk 17.0.6 2023-01-17 LTS
  • Operating System and version: Ubuntu/Alpine

Thanks for the submission. Will review soon.