@Alexander, thank you very much, the `pocketchangeapp` helped me a
lot. But I met something not included in that project, now I have
something wrong I can't resolve. Please help me.
I have a `question` class, which contains some `comments`, the
comments are embedded array of question, so I defined:
class Question(val user: User) extends MongoObject with Oid {
var title: String = _
var comments: List[QComment] = Nil
}
object Question extends MongoObjectShape[Question] { shape =>
lazy val collection = db.getCollection("questions") of Question
lazy val user = Field.ref("user", User.collection, _.user)
lazy val title = Field.scalar("title", _.title, (q: Question, v:
String) => q.title = v)
// ******************* following seems not correct
object comments
extends ArrayEmbeddedField[QComment]("comments", _.comments,
Some((x: Question, v: Seq[QComment]) => { x.comments = v.toList }))
with QCommentIn[Question]
lazy override val * = user :: title :: comments :: Nil
override def factory(dbo: DBObject) = for (user(u) <- Some(dbo))
yield new Question(u)
// ******************
}
class QComment(val question: Question) extends MongoObject with Oid {
var content: String = _
}
trait QCommentIn[T] extends ObjectIn[QComment, T] {
lazy val question = Field.ref("question", Question.collection,
_.question)
lazy val content = Field.scalar("content", _.content, (c: QComment,
v: String) => c.content = v)
lazy override val * = question :: content :: Nil
override def factory(dbo: DBObject) = for (question(q) <- Some(dbo))
yield new QComment(q)
}
object QComment extends ObjectShape[QComment] with
QCommentIn[QComment] {}
Please help me check the code, it can't pass compilation.
On 3月20日, 下午4时45分, Alexander Azarov <
aza...@aha.ru> wrote:
> 20.03.2011 at 11:41, Freewind wrote
>
> > After 1 day of tring, I have to say, it's hard to start with this
> > project. I mean, for the one-to-many, many-to-many, embedded array,
> > and so on, there is no good demo to learn.
>
> The project's Specs cover most of these:
>
>
https://github.com/osinka/mongo-scala-driver/tree/master/src/test/sca...