In our model we have a gender enumeration defined like so:
object Gender extends Enumeration {
type Gender = Value
val Male = Value(0, "male")
val Female = Value(1, "female")
val Other = Value(2, "other")
implicit val genderFormat = new PFormat[Gender.Value] {
def reads(json: JsValue) = JsSuccess(Gender.withName(json.as[String]))
def writes(myEnum: Gender.Value) = JsString(myEnum.toString)
}
}
case class User(userName: String,
firstName: Option[String] = None,
lastName: Option[String] = None,
gender: Option[Gender.Value] = None,
imageUrl: Option[String] = None,
tel: Option[String] = None,
override val id: Long = 0L) extends ActiveRecord with Datestamps
Using this code, the following test fails
"persist the gender correctly" in {
val userGender = Some(Gender.Other)
val user = User("name", gender = userGender)
user.gender mustEqual userGender
user.save()
User.where(_.userName === "name").head.gender mustEqual userGender
After calling the save() method, the gender field in the user becomes a Some(2) instead of a Some(Gender.Other)
Can you please help us on that? I read that squeryl handles enums properly.
In our model we have a gender enumeration defined like so:
Using this code, the following test fails
After calling the
save()method, the gender field in the user becomes aSome(2)instead of aSome(Gender.Other)Can you please help us on that? I read that squeryl handles enums properly.