Search code examples
scalaplayframeworkslickslick-3.0play-slick

Compiled query doesn't recognize 'exists' method


I am facing a lot of trouble while updating my application from play 2.3.x to play 2.4.11.

I started by updating play-slick from version 0.8.1 to 1.1.1, which implies updating slick from 2.1.0 to 3.1.0.

I have a generic class which aggregates the basic method like findById.

The problem I am facing at this moment is:

I had this method working as well:

def existsById(id: Long)(implicit s: Session): DBIO[Boolean] = 
    tableReference.filter(_.id === id).exists.result

I decided to use compiled queries, so I did as following:

private val queryById = Compiled((id: Rep[Option[Long]]) => tableReference.filter(_.id === id))

def existsById(id: Option[Long])(implicit s: Session): DBIO[Boolean] =
    queryById(id).exists.result

and now, I am getting an error saying that

Cannot resolve symbol exists

Am I doing it wrong? or is it a bug?


Solution

  • After you've "lifted" a Query into a Compiled you have to use map to transfrom it to a diferent Query. For example:

    val existsById = queryById.map(q => (id: Rep[Long]) => q(id).exists)