diff --git a/src/main/java/org/javawebstack/orm/Model.java b/src/main/java/org/javawebstack/orm/Model.java index 9619dbd..7a60a73 100644 --- a/src/main/java/org/javawebstack/orm/Model.java +++ b/src/main/java/org/javawebstack/orm/Model.java @@ -251,7 +251,7 @@ public Query belongsToMany(Class other, Repo selfRepo = Repo.get(getClass()); Repo otherRepo = Repo.get(other); Object id = selfRepo.getInfo().getField(selfFieldName).get(this); - return otherRepo.whereExists(pivot, q -> { + return otherRepo.query().whereExists(pivot, q -> { q.where(pivot, selfPivotFieldName, "=", id).where(pivot, otherPivotFieldName, "=", other, otherFieldName); if (pivotFilter != null) q = pivotFilter.apply(q);