Fix issue #1427, ignore parent in query when using delegate "as"

This commit is contained in:
Joel Takvorian 2015-07-06 10:18:04 +02:00
parent a187caa58e
commit 117f4e66c7
2 changed files with 2 additions and 8 deletions

View File

@ -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;
}

View File

@ -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");
}