Play2 and Anorm, how do I make the One in a One to Many relationship aware of it's Manys

扶醉桌前 提交于 2019-12-06 06:21:32

Since I got no answer I will provide my own:

In the case class I define:

case class User(id: Pk[Long] = NotAssigned,
                firstName: String,
                lastName: String,
                email: String,
                emailValidated: Boolean,
                lastLogin: DateTime,
                created: DateTime,
                modified: DateTime,
                active: Boolean) {

lazy val linkedAccounts: Seq[LinkedAccount] = DB.withConnection("test") { implicit connection =>
    SQL(
      """
        select * from linked_account la
        join users on la.user_id = users.id
        where la.id = {id}
      """
    ).on(
      'id -> id
    ).as(LinkedAccount.simple *)
  }
}

And then get the accounts by:

val linkedAccounts = user.linkedAccounts

Found this here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!