当Option [String]为None时,插入Option [String]的正确方法是什么?下面的代码插入一个空字符串,它与mysql中的NULL不同。
是否是根据partnerCode的内容预先构建SQL字符串的唯一方法?叹息... ... ANORM
DB.withConnection { implicit connection =>
val id: Option[Long] = SQL(
"""
INSERT INTO users (email, partner_code, is_active, created, pass) VALUES ({email}, {partnerCode}, 0, NOW(), {pass})
"""
).on(
'email -> user.email,
'partnerCode -> user.partnerCode.getOrElse(""), // FIXME: how to use NULL keyword instead of empty string? Is Anorm just this dumb?
'pass -> hashPassword(user.password.get)
).executeInsert()
id.get
}
答案 0 :(得分:2)
None
或anorm._
, anorm.toParameterValue
实际上应该可以正常工作:
'partnerCode -> user.partnerCode