-
Hi! @Include(name = "posts")
@Entity
public class Post {
@Id
private UUID id;
@Embedded
private Audit creation;
@Embedded
private Audit modification;
}
@Embeddable
public class Audit {
@ManyToOne
private User user;
private LocalDateTime dateTime;
}
@Include(name = "users")
@Entity
public class User {
@Id
private UUID id;
} Since entities are being bound in a random order, if it happens that the Post entity is bound ahead of the User entity, then the /users endpoint won't be exposed. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 15 replies
-
That sounds like a bug. I've never seen that behavior. What data store are you using? Are you using the multiplex store? Can you reproduce this with a small project based on elide-spring-boot-example? |
Beta Was this translation helpful? Give feedback.
-
Thanks. I can reproduce the issue. There is a bug here for sure. Will provide an update soon. |
Beta Was this translation helpful? Give feedback.
-
I did a bit of digging. The problem is that there is an Elide mode (Post) which has an embedded attribute (Audit) which contains a relationship to another model (User). From a JSON-API perspective - attributes and relationships are two different concepts. An attribute does not reference/contain a relationship. There is no way to express this in the API (even though JPA allows this kind of modeling). What you can do is to pull properties from the User model into the Audit embedded attribute to get a similar effect. Let me know if this makes sense. |
Beta Was this translation helpful? Give feedback.
-
Elide treats embedded bindings different from standard model bindings. An ID field is not required and they are not exposed as API endpoints. When Elide processes Post first, it discovers the embedded attribute Audit. It then attempts to bind the hierarchy of classes that make up that attribute. In the process of doing this, it discovers User and binds it as an embedded model. Later when the User model is bound by the JPA store, it discovers that it is already bound (this is why it is not exposed). There are two behaviors we could explore:
My suggestion is to create a separate class with the subset of User properties you want to expose - and make that embedded. |
Beta Was this translation helpful? Give feedback.
-
Here is a patch. I need to add a test, but you can try it out if you want. |
Beta Was this translation helpful? Give feedback.
Here is a patch. I need to add a test, but you can try it out if you want.
#2535