Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting Slick query results in a for expression

The following function works fine, but I would like it to sort the results first by parent_id, and then by order.

def getTree = for {
  (a, c) <- Activities leftJoin Clients on (_.id === _.id_a)
} yield (a.id, a.label, a.parent_id, a.order, c.id.?, a=c.name)

How do I do that using Slick?

like image 427
Jack Avatar asked Jan 16 '13 20:01

Jack


2 Answers

Like with ordinary collection ?

getTree.sortBy(r => r._3 ~ r._4)
like image 159
idonnie Avatar answered Sep 23 '22 05:09

idonnie


With Slick 2.1, I found this to work:

myQuery.sortBy(r => (r._3, r._4))

(verified by calling selectStatement on my query)

like image 32
Andrew Swan Avatar answered Sep 21 '22 05:09

Andrew Swan