I have the following query:
for {
post <- AllPosts
result <- Likes
.leftJoin(_.postId == post.id)
.groupBy(_ => post.id)
.map {
case (_, likes) => (
post,
likes.size,
Likes.filter(l => l.postId == post.id && l.userId == lift(userId)).size > 0
)
}
} yield result
but when I change AllPosts
(which is query[Post]
) to ApprovedPosts
(which is AllPosts.filter(_.isApproved)
) I get:
java.lang.IllegalArgumentException: requirement failed: Found an `ON` table reference of a table that is not available: Set(x1). The `ON` condition can only use tables defined through explicit joins.
which is a bit too cryptic for me. Is there a way to reuse ApprovedPosts
, or do I need to use AllPosts
and repeat the filters explicitly? (The filter works if I put it after the leftJoin
.)