mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
Fix issue #1427, ignore parent in query when using delegate "as"
This commit is contained in:
parent
a187caa58e
commit
117f4e66c7
@ -326,7 +326,8 @@ public abstract class MongodbSerializer implements Visitor<Object, Void> {
|
||||
if (metadata.getParent() != null) {
|
||||
if (metadata.getPathType() == PathType.COLLECTION_ANY) {
|
||||
return visit(metadata.getParent(), context);
|
||||
} else if (metadata.getParent().getMetadata().getPathType() != PathType.VARIABLE) {
|
||||
} else if (metadata.getParent().getMetadata().getPathType() != PathType.VARIABLE
|
||||
&& metadata.getParent().getMetadata().getPathType() != PathType.DELEGATE) {
|
||||
String rv = getKeyForPath(expr, metadata);
|
||||
return visit(metadata.getParent(), context) + "." + rv;
|
||||
}
|
||||
|
||||
@ -59,8 +59,6 @@ public class PolymorphicCollectionTest {
|
||||
|
||||
@Test
|
||||
public void countFishFromNameAndBreedWithCast() {
|
||||
// Fails because generated query is { "name" : "f1" , "food.breed" : "unknown"}
|
||||
// instead of { "name" : "f1" , "breed" : "unknown"}
|
||||
assertEquals(where(QFood.food.name.eq("f1")
|
||||
.and(QFood.food.as(QFish.class).breed.eq("unknown"))).fetchCount(), 1);
|
||||
}
|
||||
@ -70,11 +68,6 @@ public class PolymorphicCollectionTest {
|
||||
assertEquals(where(isFish()).fetchCount(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countFishesWithInstanceOf() {
|
||||
assertEquals(where(QFood.food.instanceOf(Fish.class)).fetchCount(), 2);
|
||||
}
|
||||
|
||||
private Predicate isFish() {
|
||||
return QFood.food.name.startsWith("f");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user