fatlog
fatlog

Reputation: 1192

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!

Upvotes: 0

Views: 1937

Answers (1)

Sergey
Sergey

Reputation: 2900

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:

  • replace if with filter,
  • or put the if after the take,
  • or apply the take to the result of the for comprehension

Upvotes: 3

Related Questions