2

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.)

Isvara
  • 3,403
  • 1
  • 28
  • 42
  • The thing is happening when you use filter before join, is [WHERE clause before inner join](https://stackoverflow.com/questions/10133356/where-clause-before-inner-join/10133436), Please read this and let me know if that helped :) – AminMal Jul 18 '21 at 10:15

0 Answers0