1
votes

I am trying to write a findById(pk: Long) and an update() function for a model I have created using SLICK. However in my findById method it says returns a compilation error of "value filter is not a member of object models.About" and highlights the model name About in the findById method.

    package models

//import scala.slick.driver.PostgresDriver.simple._
import play.api.db.slick.Config.driver._


case class About(
    id:Option[Long],
    name: String, 
    subheading: String, 
    about: String
)

object About extends Table[About]("about"){
    def id = column[Long]("id", O.PrimaryKey, O AutoInc) 
    def name = column[String]("name")
    def subheading = column[String]("subheading")
    def about = column[String]("about")

    def * = id.? ~ name ~ subheading ~ about <> (About.apply _, About.unapply _)

    def update(id: Long, about: About)(implicit session: Session) = findById(id).update(about)

    def findById(pk: Long) =
        for (a <- About if a.id === pk) yield a

}
2

2 Answers

3
votes

Replace your findById with:

def findById(pk: Long) =
    for (a <- Query(About) if a.id === pk) yield a

Maybe you will have to add import simple._ under the driver import.

1
votes

Also, you can use this method too:

def findById(id: Int) = {
    byId(id).list.headOption
}

and import scala.slick.jdbc.{ GetResult, StaticQuery }