Hi, I am trying to write a cypher query to get all the related nodes and relationships of a matched node.
Here is my node relationship
A vehicle (V) has Part(s) (P1 and P2). Parts can be bought from dealers (D1, D2 and D3). Part themselves can be linked to each other (for e.g P2 is linked with P1)
I am trying to write a cypher query to get a Part node matching an id. I want to get the node along with its related nodes and relationships.
When I run the query passing id of Part P1, I get the correct result. However, when I run it passing id of Part P2, I get an exce ```ption :
org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size: expect``ed at most 1
which I understand is because in this case two parts are getting returned.
I would like to know the cypher query syntax so that I get correct result (i.e P2) along with its related nodes when I pass id of P2. I want that the P1 node should also be returned as P2 is linked with P1.
Thanks for your reply. However, my requirement is that when I the pass Part.id="P1" only part P1 should be returned (Part P2 should not be returned as there is no "IS_LINKED_WITH" relationship from P1 to P2 (direction is important)) .
When I pass Part.id="P2", Part P2 should be returned with Part P1 set in it, as there is "IS_LINKED_WITH" relationship from P2 to P1 (direction is important).
Also, a vehicle can have many parts ( not just P1, P2). I have just simplified the diagram for brevity hence we will have to use Part.id to select specific parts.
I am not sure what should be the return type of the method findByIdForGivenPart so that it only returns the selected Part along with its related nodes.
Hope I have made the requirement clear.
Thanks again for your help and appreciate your time.
Thanks for your reply Michael.
Yes, I want that when I pass part.id="P1" it should only return P1 whereas when I pass part.id="P2" it should return both P1 and P2. (but I want that P1 should be set within P2) . It shouldn't be returned as separate node in the result (hope you get what I mean)
I have now changed the query to the following:
So now it returns both Parts P1 and P2 when part.id="P2"( P1 is returned as separate Part and is also set within P2). I now filter out P1 on the java side and only retaining P2 (with P1 set within it)
I want that it should not return P1 as separate node at all (and avoid the overhead of filtering it out).
I need to fetch an Image by its id, and also fetch the Creation related to it, the Pattern related to this Creation, and the imgRepresent (the Image that represent this Pattern).
Unfortunately repo.findCustById(123) throws the error " Incorrect result size: expected at most 1".
I've changed the return type to List< Image > findCustById(String id);
to see what's returned, and indeed I have 2 Image objects, the one with the id 123, but also the one which is in Pattern.imgRepresent.
Is there a solution here to only get the Image corresponding to the filter id=123, and the nested Image only in Pattern, and not in resultset?