jakob
jakob

Reputation: 6005

Left JOIN with AND clause in ON with scalikejdbc

So I have this sql(part of a much larger query):

from Person p left join ForeignCredentials fc on fc.person_id = p.id and fc.type = 'FACEBOOK'

and I'm trying to represent this in scalalikejdbc like this:

select.from(Person as p).leftJoin(ForeignCredential as fc).on(fc.`person_id`, p.id)

But I can't figure out how to ad the extra condition. The intuitive way would be:

    select.from(Person as p).leftJoin(ForeignCredential as fc).on(fc.`person_id`, p.id)
.and.eq(fc.`type`, "FACEBOOK").

So how do I do it?

Upvotes: 3

Views: 557

Answers (1)

Kazuhiro Sera
Kazuhiro Sera

Reputation: 1877

The following should work for you.

on(sqls.eq(fc.`person_id`, p.id).and.eq(fc.`type`, "FACEBOOK")) 

https://github.com/scalikejdbc/scalikejdbc/blob/2.2.8/scalikejdbc-interpolation/src/main/scala/scalikejdbc/QueryDSLFeature.scala#L408-L411

Upvotes: 3

Related Questions