Skip to content

Instantly share code, notes, and snippets.

@kamekoopa
Created October 1, 2013 03:34
Show Gist options
  • Save kamekoopa/6773533 to your computer and use it in GitHub Desktop.
Save kamekoopa/6773533 to your computer and use it in GitHub Desktop.
scalikejdbcでフィールド名の解決に失敗する?
case class Hoge(id: String)
object HogeTable extends SQLSyntaxSupport[Hoge]{
//ry
}
//これだとh.idのコンパイルが失敗する
def doSomething() = {
findOther.right.flatMap { result => //Eitherを返すDB処理
val h = HogeTable.syntax("h")
withSQL {
select
.from(HogeTable as h)
.where.eq(h.id, "id")
}
//.map(ry)
.single()
.apply()
.toRight(new Exception("not found"))
}
}
//これだとOK
def doSomething() = {
val hid = h.id
findOther.right.flatMap { result => //Eitherを返すDB処理
val h = HogeTable.syntax("h")
withSQL {
select
.from(HogeTable as h)
.where.eq(hid, "id")
}
//.map(ry)
.single()
.apply()
.toRight(new Exception("not found"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment