我有这个域对象:
case class Person (
name : String,
age: Option[Int],
email : String
) extends MongoObject
带有年龄可选字段。所以我定义了我的工厂:
object Person extends MongoObjectShape[Person] {
lazy val name = Field.scalar("name", _.name)
lazy val age = Field.optional("age", t => t.age)
lazy val email = Field.scalar("email", _.email)
override lazy val * = name :: age :: email :: Nil
override def factory(dbo: DBObject): Option[Person] =
for {
n <- name from dbo
t <- age from dbo
z <- email from dbo
} yield new Person(n, t, z)
}
但它不编译,因为我得到:
[error] found : Int
[error] required: Option[Int]
[error] } yield new Person(n, t, z)
[error] ^
这有什么问题?