Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick 3.0.0 - How to sortBy on a query with joinLeft

This question is related to another. I'm also trying to sort on a query with a joinLeft but in slick 3.0.0. And as the Option Rep are automatically lifted how would I do the exact same thing ?:

def list(filter: String, orderBy: Int):Future[Seq[(Computer, Option[Company])]] = {
    val initialQuery = for {
        (computer, company) <- Computer.filter(_.name like filter) leftJoin 
            Company on (_.companyId === _.id)
    } yield (computer, company)

    val sortedQuery = orderBy match {
        case 2 => initialQuery.sortBy(_._1.name) //Works ok, column from a primary table
        case 3 => initialQuery.sortBy(_._2.map(_.name)) //could not find implicit value for parameter ol: slick.lifted.OptionLift[slick.lifted.ColumnOrdered[String],slick.lifted.Rep[Option[QO]]]
    }
    db.run(sortedQuery.result)
}

Thanks,

like image 403
Camille Wanty Avatar asked Sep 15 '15 16:09

Camille Wanty


1 Answers

I suppose that missing parenthesis is just a typo. I had this problem recently when I was specifying the sort direction in the wrong place, using your example:

case 3 => initialQuery.sortBy(_._2.map(_.name.asc))

It should be:

case 3 => initialQuery.sortBy(_._2.map(_.name).asc)
like image 200
Bartosz Bąbol Avatar answered Sep 23 '22 10:09

Bartosz Bąbol