Closed andersgb closed 7 years ago
Would the following work?
ctx.run {
query[Entity]
.filter(e => query[Record]
.filter(_.id == lift(exampleId))
.map(_.groupId)
.contains(e.recordGroup)
)
}
@zifeo Thanks, that does the trick!
Dunno if formulating the query as I proposed should be supported, feel free to close this issue.
@andersgb or even like this (produce query as in expected clause)
ctx.run {
query[Record]
.filter(_.id == lift(exampleId))
.map(r => r.groupId)
.flatMap(groupId => query[Entity].filter(_.recordGroup.exists(_ == groupId)))
}
// SELECT x2.recordGroup FROM Record x1, Entity x2 WHERE (x1.id = ?) AND (x2.recordGroup = x1.groupId)
Consider using exists
/forall
for comparing raw values to options.
structure x == Option(y)
(if x and y parts of queries) is not supported,
@fwbrasil any ideas how to be with this issue, enhancement or won't do?
@mentegy thanks, that's closer to how my original proposal. I did not know exists
, forall
and even contains
on the Option could be used here.
Since x.contains(y)
works, I don't see a need for x == Option(y)
. A more informative error message and/or documentation on this would be great, though.
2.0.0-SNAPSHOT
already fails with a better error message: https://github.com/getquill/quill/pull/904
Version:
1.2.1
Module:quill-jdbc
Database:mysql
Steps to reproduce the behavior
I want to query two tables where I match an Option value to a non-Option value. This is similar to #584, but here my Option value is not originating from outside the query (i.e. we cannot use
lift(Option(value))
).Expected behavior
Something along the lines of this SQL query:
Actual behavior
Compilation error:
Workaround
I can split the query into two:
But that's not really a good solution. Any better workarounds? @getquill/maintainers