Mongodb: cast with "as" in query produces unexpected result #1427

Closed
jotak opened this Issue Jul 3, 2015 · 1 comment

Projects

None yet

2 participants

@jotak
Contributor
jotak commented Jul 3, 2015

I'm trying to cast a class in a query on mongodb, but it doesn't work as I would expect.

I wrote some unit tests to illustrate, you can see it here: jotak@28756b9

2 of my tests fail:

  • "countCatsWithInstanceOf": quite unrelated, but worth mentioning: "instanceOf" doesn't seem to be supported
  • "countFishFromNameAndBreedWithCast" : this illustrates the bug. When running
    .and(QFood.food.as(QFish.class).breed.eq("unknown"))

the json produced is

{ "name" : "f1" , "food.breed" : "unknown"}

instead of expected:

{ "name" : "f1" , "breed" : "unknown"}

So it returns 0 result

For information, this ticket follows what I wrote on discussion board: https://groups.google.com/forum/#!topic/querydsl/KaUWIUwov6w

@jotak jotak added a commit to jotak/querydsl that referenced this issue Jul 6, 2015
@jotak jotak Fix issue #1427, ignore parent in query when using delegate "as" 4f05c17
@jotak jotak added a commit to jotak/querydsl that referenced this issue Jul 6, 2015
@jotak jotak Fix issue #1427, ignore parent in query when using delegate "as" 117f4e6
@jotak
Contributor
jotak commented Jul 6, 2015

Just made a pull request #1428

I leave the "instanceOf" unsupported operation issue. Looks like the user must handle it his way. Maybe however we could imagine adding a kind "instanceOf" hooks in metadata, written by the user, so that the operation can be supported in mongodb.

@timowest timowest added the progress label Jul 17, 2015
@johnktims johnktims closed this in #1428 Jul 21, 2015
@timowest timowest removed the progress label Jul 21, 2015
@timowest timowest added this to the 4.0.3 milestone Jul 21, 2015
@jotak jotak added a commit to jotak/querydsl that referenced this issue Jul 22, 2015
@jotak jotak Fix issue #1427, ignore parent in query when using delegate "as" 2577359
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment