0

I'm trying to implement a request like in example in documentation: http://squeryl.org/joins.html

I have a table "Requisite" and "Service". In field "paymentRequisite" of table Service could be a link to row of Requisite or Null:

@Column("paymentRequisite")
var paymentRequisite: Option[Long], 

I have a request like this:

inTransaction {
     join(AppDb.paymentRequisite, AppDb.catalogService.leftOuter)((p, c) => 
       compute(p.id, count(c.map(_.id))) 
       on(p.id === c.map(_.paymentRequisite))).toList
}

But this throws an exception:

[error]  found   : Option[Option[Long]]
[error]  required: org.squeryl.dsl.NumericalExpression[?]

It's because of _.paymentRequisite

Finally, what I'm trying to select ReqId and count of Services which reference to this requisite.

jcern
  • 7,798
  • 4
  • 39
  • 47
Pavel Varchenko
  • 727
  • 1
  • 11
  • 21

1 Answers1

0

I found the solution =)

inTransaction {
     join(AppDb.paymentRequisite, AppDb.catalogService.leftOuter)((p, c) => 
       groupBy(p.id) 
       compute(p.id, count(c.map(_.id))) 
       on(Some(p.id) === c.flatMap(_.paymentRequisite))).toList
}
jcern
  • 7,798
  • 4
  • 39
  • 47
Pavel Varchenko
  • 727
  • 1
  • 11
  • 21