scalaslickslick-2.0

Slick - Join Table with Rows Limit


I'm using Slick 2.1 and am doing a fairly standard JOIN. However when I try to limit the number of rows returned using "take()" I get a compile error.

Query...

var samples = for {
(sample, user) <- this 
      .join(users) on (_.userId === _.id) if user.id === 123
      .take(50)
  } yield (sample)

The compiler error...

type mismatch;  found   : Iterable[String]  required: scala.slick.lifted.Column[?]

Why can I not simply add in "take()" here?!

Thanks!


Solution

  • Actually your expression is invalid syntactically: you've inserted a for-comprehension guard statement before trying to make another call in the chain of table transformations.

        .join(users) on (_.userId === _.id) if user.id === 123
                                            ^ Right here
        .take(50)
    

    To fix, you have one of three options: