Reputation: 135
I have a table with a tuple (2 different columns) as my primary key. I am trying to make a function findByPrimaryKeys(pks: Vector[(Long, Long)])
that returns a query for all the rows with a primary key in the set pks
. However, it seems there is no way to do this, I can do
table.filter(t => t.id1.inSet(pks.map(_._1)) && t => t.id2.inSet(pk2.map(_._2)))
However, this is not exactly correct, as it could return something that has a matching id2 but not id1.
Is there way to combine Rep
s?
Upvotes: 4
Views: 439
Reputation: 4587
Yes, it's possible to combine Rep
value, there's an implicit conversion from (Rep[Long], Rep[Long])
to Rep[(Long, Long)]
. But that doesn't help in this case because inSet
is added through an implicit conversion, and that conversion requires an implicit BaseTypedType[(Long, Long)]
to be available, which it isn't.
The only way I know to solve this problem is to use a fold:
table.filter { t =>
pks.foldLeft[Rep[Boolean]](false) { case (a, (x, y)) =>
a || (t.id1 === x && t.id2 === y)
}
}
Upvotes: 1