Skip to content

Commit 17d2558

Browse files
author
P63098
committed
Fix 176 Add the ability to choose the join type with ElementCollection
1 parent c01825e commit 17d2558

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

rsql-jpa/src/main/java/io/github/perplexhub/rsql/RSQLJPAPredicateConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private RSQLJPAContext findPropertyPathInternal(String propertyPath, Path startR
144144
classMetadata = getManagedElementCollectionType(mappedProperty, classMetadata);
145145
String keyJoin = getKeyJoin(root, mappedProperty);
146146
log.debug("Create a element collection join between [{}] and [{}] using key [{}]", previousClass, classMetadata.getJavaType().getName(), keyJoin);
147-
root = join(keyJoin, root, mappedProperty);
147+
root = join(keyJoin, root, mappedProperty, joinHints.get(keyJoin));
148148
} else if (JsonbSupport.isJsonType(mappedProperty, classMetadata)) {
149149
root = root.get(mappedProperty);
150150
attribute = RSQLVisitorBase.getAttribute(mappedProperty, classMetadata);

rsql-jpa/src/test/java/io/github/perplexhub/rsql/RSQLJPASupportTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ final void testElementCollection2() {
278278
assertThat(rsql, count, is(4L));
279279
}
280280

281+
@Test
282+
final void testElementCollection1WithJoinHints() {
283+
final Map<String, JoinType> joinHints = Map.of("Company.tags", JoinType.LEFT);
284+
final String rsql = "tags!=tech,tags=na=";
285+
final List<Company> companies = companyRepository.findAll(toSpecification(rsql, null, joinHints));
286+
final long count = companies.size();
287+
log.info("rsql: {} -> count: {}", rsql, count);
288+
assertThat(rsql, count, is(4L));
289+
}
290+
291+
@Test
292+
final void testElementCollection2WithJoinHints() {
293+
final Map<String, JoinType> joinHints = Map.of("Company.bigTags", JoinType.LEFT);
294+
final String rsql = "bigTags.tag!=tech,bigTags.tag=na=";
295+
final List<Company> companies = companyRepository.findAll(toSpecification(rsql, null, joinHints));
296+
final long count = companies.size();
297+
log.info("rsql: {} -> count: {}", rsql, count);
298+
assertThat(rsql, count, is(4L));
299+
}
300+
281301
@Test
282302
final void testToComplexMultiValueMap() {
283303
String rsql = "sites.trunks.id==2,id=na=2,company.id=='2',id=na=3,name==''";

0 commit comments

Comments
 (0)