I'm trying to do a complex querying on two tables. They look like below:
Table1:
id:
name:
table2Id:
version:
Table2:
id:
comments:Assuming that I have the appropriate Slick classes that represents these tables, I'm trying to get all the elements from Table1 and Table 2 that satisfies the following condition:
Table1.table2Id === Table2.id and max(Table1.version)I tried the following:
val groupById = (for {
elem1 <- table1Elems
elem2 <- table2Elems if elem1.id === elem2.id
} yield (elem1, elem2)).groupBy(_._1.id)I know that I have to map the groupById and look for the max version, but I'm not getting the syntax right! Any help?
val orderBy = groupById.map {
case (id, grouped) => grouped.sortBy(x => x._1.version.desc).take(1)
}.result
Error:(105, 33) No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
Required level: slick.lifted.FlatShapeLevel
Source type: slick.lifted.Query[(ServiceTests.this.myService.Table1, ServiceTests.this.myService.Table2),((String, String, String, String, String, Int, java.sql.Date, java.sql.Date), (String, String, String, Boolean)),[+A]Seq[A]]
Unpacked type: T
Packed type: G
val orderBy = groupById.map {I'm trying to get the max version number from a table. Here is the sql that I came up with:
SELECT * from table1 t1
WHERE t1.conficVersion =
(SELECT max(configVersion) FROM table2 t2 WHERE t2.id = t1.id)
I'm now stuck up with writing the Slick version of it. Any suggestions, pointers? This is what I have so far:
table1.groupBy(p => p.id)
.map { case (id, group) => (id, group.map(_.version).max) }
Now how can I combine this grouped result into a proper query that will actually fetch me the max version for all the id's? Please help!