Skip to content

Commit 8bf0ab6

Browse files
jfb-NRBP63098perplexhub
authored
Fix 176 Add the ability to choose the join type with ElementCollection (#180)
Co-authored-by: P63098 <[email protected]> Co-authored-by: A F <[email protected]>
1 parent 97b70db commit 8bf0ab6

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ RSQLJPAContext findPropertyPath(String propertyPath, Path startRoot) {
139139
classMetadata = getManagedElementCollectionType(mappedProperty, classMetadata);
140140
String keyJoin = getKeyJoin(root, mappedProperty);
141141
log.debug("Create a element collection join between [{}] and [{}] using key [{}]", previousClass, classMetadata.getJavaType().getName(), keyJoin);
142-
root = join(keyJoin, root, mappedProperty);
142+
root = join(keyJoin, root, mappedProperty, joinHints.get(keyJoin));
143143
} else if (isJsonType(mappedProperty, classMetadata)) {
144144
root = root.get(mappedProperty);
145145
attribute = classMetadata.getAttribute(mappedProperty);

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,26 @@ public final void testElementCollection2() {
182182
assertThat(rsql, count, is(4l));
183183
}
184184

185+
@Test
186+
public final void testElementCollection1WithJoinHints() {
187+
final Map<String, JoinType> joinHints = new HashMap<String, JoinType>(){{put("Company.tags", JoinType.LEFT);}};
188+
final String rsql = "tags!=tech,tags=na=''";
189+
final List<Company> companies = companyRepository.findAll(toSpecification(rsql, null, joinHints));
190+
final long count = companies.size();
191+
log.info("rsql: {} -> count: {}", rsql, count);
192+
assertThat(rsql, count, is(4L));
193+
}
194+
195+
@Test
196+
public final void testElementCollection2WithJoinHints() {
197+
final Map<String, JoinType> joinHints = new HashMap<String, JoinType>(){{put("Company.bigTags", JoinType.LEFT);}};
198+
final String rsql = "bigTags.tag!=tech,bigTags.tag=na=''";
199+
final List<Company> companies = companyRepository.findAll(toSpecification(rsql, null, joinHints));
200+
final long count = companies.size();
201+
log.info("rsql: {} -> count: {}", rsql, count);
202+
assertThat(rsql, count, is(4L));
203+
}
204+
185205
@Test
186206
public final void testToComplexMultiValueMap() {
187207
String rsql = "sites.trunks.id==2,id=na=2,company.id=='2',id=na=3,name==''";

0 commit comments

Comments
 (0)