Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No implicit Ordering defined for scala.slick.lifted.ColumnOrdered[Long]

I'm using slick 2.0 via play plugin and the following is my table mapping

class Tasks(tag: Tag) extends Table[Task](tag, "Tasks"){
    def id   = column[Option[Long]]("id", O.PrimaryKey, O.AutoInc)
    def txt  = column[String]("txt")
    def done = column[Boolean]("done")
    def * = (id, txt, done) <> (Task.tupled, Task.unapply)
}

Then, I created TableQuery object like this

val tasks = TableQuery[Tasks]

I used tasks.list to get List[Task] which returns correctly but when I want to sort the result by using tasks.list.sortBy(_.id.get.desc) I got this error instead

No implicit Ordering defined for scala.slick.lifted.ColumnOrdered[Long].

Any idea?

like image 911
hussachai Avatar asked Feb 06 '26 16:02

hussachai


1 Answers

you have to sort first and then call .list():

tasks.sortBy(_.id.desc).list()

When calling list() you are executing the invoker and that's too late to add the sorting on the sql level, of course you can always sort the collection you get back using the list sortBy method.

like image 74
Ende Neu Avatar answered Feb 09 '26 10:02

Ende Neu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!