-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Projections on the discriminator property fail #2939
Comments
What's the use case for doing a projection on the discriminator? Such metadata should be ignored/transparent to your application? |
I have an Entity which contains a property that is an interface. When I add a projection on the fields of one of the subtypes of the interface, it doesn't include the discriminatorKey to the projection. As a consequence the The
But this only gets applied to the main Entity and not it's nested interface. |
If you're querying by the interface type, you'll need to enable polymorphic queries. |
The parent entity is not an interface, so from what I understood, it wouldn't be considered a polymorphic query. The query is on the parent entity which is a concrete class, the interface is a property of the entity. @Entity
public class MyEntity {
@Id private ObjectId myId;
@Property private MyInterface prop;
}
@Entity( useDiscriminator = true )
public interface MyInterface {}
@Entity( useDiscriminator = true, discriminator = "mydisc" )
public class MyImpl implements MyInterface {
@Property private int propA;
... more properties
} The query is on MyEntity and I am adding a projection on the properties in MyImpl e.g. "prop.propA" In this case the Morphia does not include the discriminatorKey into the projection and so the decoding of the MyInterface property fails. |
What does your query look like? |
I've tried to replicate the query as closely as possible in terms of filters and options used. Obviously not all the fields match above, but I've tried to keep the entity and embedded entity references accurate.
|
I'm not seeing how/where the discrimininator come in to play. Is the failure you're seeing that the projection doesn't know how to "see past" the interface definition? |
If I include the discriminator in the projection, then the If I don't include the discriminator in that projection, then the |
If you could put together a reproducer I can take a deeper look. I have some ideas about what might be happening here but I can't quite follow your examples here well enough to be confident in recreating your scenario. |
Describe the bug
When creating a projection on a discriminator property, the
PathTarget
throws aValidationException
because the discriminator is not added to theEntityModel
as aPropertyModel
.Note that the same issue will be present on any use of the
PathTarget
that involves the discriminator and doesn't skip validation.To Reproduce
Expected behavior
It should be possible to add a projection on the discriminator property.
** Please complete the following information: **
The text was updated successfully, but these errors were encountered: