Slick Error Message: 'value tupled is not a member of object'

Slick Error Message: 'value tupled is not a member of object'

Last updated:

Sometimes when declaring classes and projections in Slick you get stuck with the following error message:

value tupled is not a member of object

This looks like it's caused by a known bug. There's also a github discussion on that very issue here and some discussion of potential workarounds.

This happens when you declare a companion object with the same name as the case class and try to base a slick table on it

I applied the mentioned workaround when defining the *projection; look at the following snippet:

package models

import java.sql.Date
import play.api.db.slick.Config.driver.simple._
import play.api.Play.current
import scala.slick.lifted.Tag

case class User(
  id: Long,
  username: String,
  email: Option[String],
  password: String,
  createdAt: Date)

class Users(tag: Tag) extends Table[User](tag, "users") {

  def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
  def username = column[String]("username", O.NotNull)
  def email = column[String]("email", O.Nullable)
  def password = column[String]("password", O.NotNull)
  def createdAt = column[Date]("createdAt", O.NotNull)

  // workaround successfully applied
  def * = (id, username, email.?, password, createdAt) <> ((User.apply _).tupled, User.unapply)

}

object User{
    val users = TableQuery[Users]

   //perhaps some helper methods here, such as
   def findById(id: Long)(implicit s: Session): Option[User] = {
       //returns option(list(0))
        users.filter(_.id === id).list.headOption
   }
}

It seems that this error occurs when you have a class (which defines a database table) and a companion object with the same name.

References

Dialogue & Discussion