Skip to content

Commit d4fd200

Browse files
committed
nativeLink now receives relationOwnerEntityId instead of sourceEntityId
1 parent 2d48928 commit d4fd200

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

objectbox-java/src/main/java/io/objectbox/query/QueryBuilder.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ enum Operator {
110110

111111
private native long nativeBuild(long handle);
112112

113-
private native long nativeLink(long handle, long storeHandle, int sourceEntityId, int targetEntityId,
113+
private native long nativeLink(long handle, long storeHandle, int relationOwnerEntityId, int targetEntityId,
114114
int propertyId, int relationId, boolean backlink);
115115

116116
private native void nativeOrder(long handle, int propertyId, int flags);
@@ -286,13 +286,15 @@ public QueryBuilder<T> sort(Comparator<T> comparator) {
286286
* @return A builder to define query conditions at the target entity side.
287287
*/
288288
public <TARGET> QueryBuilder<TARGET> link(RelationInfo<TARGET> relationInfo) {
289-
return link(relationInfo, relationInfo.sourceInfo, relationInfo.targetInfo, relationInfo.isBacklink());
289+
boolean backlink = relationInfo.isBacklink();
290+
EntityInfo relationOwner = backlink ? relationInfo.targetInfo : relationInfo.sourceInfo;
291+
return link(relationInfo, relationOwner, relationInfo.targetInfo, backlink);
290292
}
291293

292-
private <TARGET> QueryBuilder<TARGET> link(RelationInfo relationInfo, EntityInfo source, EntityInfo target,
294+
private <TARGET> QueryBuilder<TARGET> link(RelationInfo relationInfo, EntityInfo relationOwner, EntityInfo target,
293295
boolean backlink) {
294296
int propertyId = relationInfo.targetIdProperty != null ? relationInfo.targetIdProperty.id : 0;
295-
long linkQBHandle = nativeLink(handle, storeHandle, source.getEntityId(), target.getEntityId(), propertyId,
297+
long linkQBHandle = nativeLink(handle, storeHandle, relationOwner.getEntityId(), target.getEntityId(), propertyId,
296298
relationInfo.relationId, relationInfo.isBacklink());
297299
return new QueryBuilder<>(storeHandle, linkQBHandle);
298300
}
@@ -314,8 +316,7 @@ public <TARGET> QueryBuilder<TARGET> backlink(RelationInfo relationInfo) {
314316
if (relationInfo.isBacklink()) {
315317
throw new IllegalArgumentException("Double backlink: The relation is already a backlink, please use a regular link on the original relation instead.");
316318
}
317-
318-
return link(relationInfo, relationInfo.targetInfo, relationInfo.sourceInfo, false);
319+
return link(relationInfo, relationInfo.sourceInfo, relationInfo.sourceInfo, true);
319320
}
320321

321322
/**

0 commit comments

Comments
 (0)