Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working samples of PLAY 2.6 + SCALIKEJDBC 3.2 #30

Closed
mado-m opened this issue Jun 17, 2019 · 3 comments
Closed

Not working samples of PLAY 2.6 + SCALIKEJDBC 3.2 #30

mado-m opened this issue Jun 17, 2019 · 3 comments
Assignees
Labels

Comments

@mado-m
Copy link
Contributor

mado-m commented Jun 17, 2019

元ソース

def list = Action { implicit request =>
  DB.readOnly { implicit session =>
    // ユーザのリストを取得
    val users = withSQL {
      select.from(Users as u).leftJoin(Companies as c).on(u.companyId, c.id).orderBy(u.id.asc)
    }.map { rs =>
      (Users(u)(rs), rs.intOpt(c.resultName.id).map(_ => Companies(c)(rs)))
    }.list.apply()

    // 一覧画面を表示
    Ok(views.html.user.list(users))
  }
}

下記のように val u = Users.syntax("u") を追記することでコンパイルエラーは回避できました。

def list = Action { implicit request =>
val u = Users.syntax("u")

DB.readOnly { implicit session =>
    // ユーザのリストを取得
    val users = withSQL {
    select.from(Users as u).leftJoin(Companies as c).on(u.companyId, c.id).orderBy(u.id.asc)
    }.map { rs =>
    (Users(u)(rs), rs.intOpt(c.resultName.id).map(_ => Companies(c)(rs)))
    }.list.apply()

    // 一覧画面を表示
    Ok(views.html.user.list(users))
}
}
@mado-m mado-m self-assigned this Jun 17, 2019
@mado-m
Copy link
Contributor Author

mado-m commented Jun 27, 2019

from #31

最後の Ok(Json.obj("users" -> users)) の箇所のimplicitが見つからないみたい?
ドキュメント通りにimport JsonController._を書いてあるがダメ。

  def list = Action { implicit request =>
    val u = Users.syntax("u")

    DB.readOnly { implicit session =>
      // ユーザのリストを取得
      val users = withSQL {
        select.from(Users as u).orderBy(u.id.asc)
      }.map(Users(u.resultName)).list.apply()

      // ユーザの一覧をJSONで返す
      Ok(Json.obj("users" -> users))
    }
  }

@mado-m
Copy link
Contributor Author

mado-m commented Jun 27, 2019

from #32

元ソース

"""{"users":[{"id":1,"name":"Taro Yamada","companyId":1},{"id":2,"name":"Jiro Sato"}]}"""

下記のように"companyId":nullを明記すると通る。nullを返すかどうかなのでバージョンや設定が関係しているかも?

"""{"users":[{"id":1,"name":"Taro Yamada","companyId":1},{"id":2,"name":"Jiro Sato","companyId":null}]}"""

@mado-m mado-m closed this as completed Jun 27, 2019
@mado-m mado-m reopened this Jun 27, 2019
@mado-m mado-m changed the title PLAY 2.6 + SCALIKEJDBC 3.2 の"ジョインの必要な処理"->"コントローラの修正"のソースがエラーとなる Not working ~`PLAY 2.6 + SCALIKEJDBC 3.2 Jun 27, 2019
@mado-m mado-m changed the title Not working ~`PLAY 2.6 + SCALIKEJDBC 3.2 Not working PLAY 2.6 + SCALIKEJDBC 3.2 Jun 27, 2019
@mado-m mado-m changed the title Not working PLAY 2.6 + SCALIKEJDBC 3.2 Not working samples of PLAY 2.6 + SCALIKEJDBC 3.2 Jun 27, 2019
@mado-m
Copy link
Contributor Author

mado-m commented Jun 27, 2019

再度手順通りにやってみたら問題なく動いたので一旦閉じます。

@mado-m mado-m closed this as completed Jun 27, 2019
@mado-m mado-m added the invalid label Jun 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant