We are still working on it and we are doing some refactoring to
simplify it and remove the Entity concept. But anyway the theory stay
the same.
> How do I define associations between entities like one-to-many and
> many-to-one ? When I fetch entities with associations, is there a way to
> define how to join them ?
It's not an ORM, so you can't do that (that why we are removing the
Entity concept that was error prone).
There is several way to achieve that, but I will show you an example
with 2 tables (User and Post) and a way to fetch a list of Post with
the corresponding author using the parser combinator API:
-----
case class User(email: String, password: String, fullname: String)
case class Post(title: String, content: String, author_id: Long)
object User extends MEntity[Long,User]
object Post extends MEntity[Long,Post]
del allPosts = sql("select * from Post p join User u on p.author_id =
u.id").as( Post ~< User )
// Print the result
allPosts.foreach {
case post ~ author => println(post + " - author: " + author)
}
-----
If I add a Comment table to the game:
-----
case class Comment(author: String, content: String, post_id: Long)
object Comment extends MEntity[Long,Comment]
def findPostWithComments(id: Long) = {
sql("select * from Post p join User u on p.author_id = u.id left
join Comment c on c.post_id = p.id where p.id = {id}")
.on("id" -> id)
.as(opt( Post ~< User ~< (Comment*) ))
}
val Some(post ~ author ~ comments) = findPostWithComments(4)
-----
About boolean values we are aware of this problem. In the final
version we will support all basic type corresponding to existing JDBC
types.
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.
>
--
Guillaume Bort, http://guillaume.bort.fr
For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com
--
Guillaume Bort, http://guillaume.bort.fr
For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com