Skip to content

Commit bef8acc

Browse files
committed
GH-2928 - Handle deeply nested relationships in fluent query correctly.
Closes #2928
1 parent edbda8a commit bef8acc

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/main/java/org/springframework/data/neo4j/repository/query/FluentQuerySupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.neo4j.repository.query;
1717

18-
import java.util.Arrays;
1918
import java.util.Collection;
2019
import java.util.Collections;
2120
import java.util.HashSet;
@@ -126,7 +125,7 @@ final Collection<String> extractAllPaths(Collection<String> projectingProperties
126125
Set<String> allPaths = new HashSet<>();
127126
for (String property : projectingProperties) {
128127
if (property.contains(".")) {
129-
allPaths.addAll(Arrays.stream(property.split("\\.")).toList());
128+
allPaths.add(property.substring(0, property.lastIndexOf(".")));
130129
}
131130
allPaths.add(property);
132131
}

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,7 @@ RETURN id(n)
27932793
CREATE (f2) -[:ARRIVES] ->(cdg)
27942794
CREATE (f3) -[:DEPARTS] ->(lax)
27952795
CREATE (f3) -[:ARRIVES] ->(lhr)
2796+
CREATE (f1) -[:NEXT_FLIGHT] ->(f2) -[:NEXT_FLIGHT] ->(f3)
27962797
""");
27972798
}
27982799

@@ -2882,6 +2883,22 @@ void findAllByExampleFluentProjectingRelationships(@Autowired FlightRepository r
28822883
});
28832884
}
28842885

2886+
@Test
2887+
void findAllByExampleFluentCyclicRelationships(@Autowired FlightRepository repository) {
2888+
Example<Flight> example = Example.of(new Flight("FL 001", null, null),
2889+
ExampleMatcher.matchingAll().withIgnoreNullValues());
2890+
List<Flight> flights = repository.findBy(example,
2891+
q -> q.project("name", "nextFlight.name", "nextFlight.nextFlight.name").all());
2892+
2893+
assertThat(flights)
2894+
.hasSize(1)
2895+
.first().satisfies(p -> {
2896+
assertThat(p.getName()).isEqualTo("FL 001");
2897+
assertThat(p.getNextFlight().getName()).isEqualTo("FL 002");
2898+
assertThat(p.getNextFlight().getNextFlight().getName()).isEqualTo("FL 003");
2899+
});
2900+
}
2901+
28852902
@Test // GH-2343
28862903
void findAllByExampleFluentAs(@Autowired PersonRepository repository) {
28872904

src/test/java/org/springframework/data/neo4j/integration/shared/common/Flight.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,12 @@ public Airport getDeparture() {
5757
public Airport getArrival() {
5858
return arrival;
5959
}
60+
61+
public Flight getNextFlight() {
62+
return this.nextFlight;
63+
}
64+
65+
public void setNextFlight(Flight nextFlight) {
66+
this.nextFlight = nextFlight;
67+
}
6068
}

0 commit comments

Comments
 (0)