You have also to return the relationship.
I am assuming that the LIKES relationship is part of the Person entity, right?
A side note: please do not use SDN/RX in the future but SDN 6 (its successor).
It is available within the Spring Boot RC1 that will get released next week.
Actually, the query I've been trying looks more like
@Query("MATCH(n:Person)-[:LIKES]->(m:Movies) return n as person , count(m) as nMovies")
or even
@Query("MATCH(n:Person) return n as person , size(keys(n)) as nMagic")
So the mix is between a Person entity and an Integer (last scenario w/o relations). I just tho that giving a much more complex case was going to give me better insight. I have 'worked around' it with apoc.merge and handling it as a single @Node class. Is there another way?
About the side note, can you tell me more about the benefits of the new SDN 6? What's not so good on Rx? We have recently ported an application to the RX library and I want to be sure there's and stable version before moving again.
SDN 6 is the future of SDN/RX. There is no future work done in the RX project.
We moved all the sources to VMWare's Spring Data repository and continued the work there ~5 months ago.
Spring Data Neo4j 6 got release last week as GA and will be included in Spring Boot 2.4 next week.
What you want to do is exactly what we made possible in SDN 6: Projections.
So for example, you can define a POJO like this:
public class PersonAndMagic {
private Person person;
private long nMagic;
//...
}
I have tested this projection as you suggested on SDN 6 but I'm not getting the expected result. The extra variable (in this examle nMagic) is properly mapped but the 'original' entity is not mapped.
I modeled an example in GitHub - BennuFire/nested-relation-query-sdn6 failing on test test_projection. I would really appreciate if you can spend a couple of minute checking in case it's my mistake (even if I have tried to follow the SDN 6 documentation).
If the store optimizes the query execution by limiting the fields to be loaded, the fields to be loaded are determined from the parameter names of the constructor that is exposed
The constructor for the projection DTO is mandatory in this cases.