Skip to content

Commit

Permalink
fix(relationship): fix bug in extractRelationshipFromAspect (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdonn authored Nov 27, 2024
1 parent 783ae91 commit 3644f12
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ public static LocalRelationshipCriterion buildRelationshipFieldCriterion(LocalRe
} else if (!(obj instanceof List) || ((List) obj).isEmpty() || !(((List) obj).get(0) instanceof RecordTemplate)) {
return;
}
// filter out all non-primitive, non-relationship, non-list fields
if (!(obj instanceof List)) {
return;
}
List<RecordTemplate> relationshipsList = (List<RecordTemplate>) obj;
ModelType modelType = parseModelTypeFromGmaAnnotation(relationshipsList.get(0));
if (modelType == ModelType.RELATIONSHIP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ public void testExtractRelationshipsFromAspect() throws URISyntaxException {
// relationshipFoos -> [foo1, foo2]
// relationshipBars -> [bar1]
// moreRelationshipFoos -> not present
// nonPrimitiveNonRelationshipField -> commonAspect2
// }
// expect:
// [[foo1, foo2], [bar1]]
Expand All @@ -655,7 +656,8 @@ public void testExtractRelationshipsFromAspect() throws URISyntaxException {
.setRelationshipFoo1(test3)
// don't set relationshipFoo2 fields
.setRelationshipFoos(relationshipFoos)
.setRelationshipBars(relationshipBars); // don't set moreRelationshipFoos field
.setRelationshipBars(relationshipBars) // don't set moreRelationshipFoos field
.setNonPrimitiveNonRelationshipField(new CommonAspect());

results = EBeanDAOUtils.extractRelationshipsFromAspect(barWithRelationshipFields);
assertEquals(2, results.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ record AnnotatedAspectBarWithRelationshipFields {
* For unit tests
*/
moreRelationshipFoos: optional array[AnnotatedRelationshipFoo]

/**
* For unit tests
*/
nonPrimitiveNonRelationshipField: optional CommonAspect
}

0 comments on commit 3644f12

Please sign in to comment.