--
You received this message because you are subscribed to the Google Groups "mapperdao" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapperdao+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
follow up question:
After setting up this oneToMany relation I also wanted to make it lazy, but was unable.here is the setup followed up by a little more info:
sealed abstract class Role(dbName: String)object Role {
case object Admin extends Role("Admin")
case object Premium extends Role("Premium")
case object Unknown extends Role("Unknown")
def roles: Seq[Role] = List(Admin, Premium, ContentUploader, Unknown)
def fromString(s: String) = roles find { _.toString == s } getOrElse(Unknown)}
case class User(id:Long, bla bla, roles:Set[Role]=Set.empty[Role])
object UserEntity extends Entity[Long, SurrogateLongId, User]("users") {
val RolesEntity = StringEntity.oneToMany("users_roles","unused fk", "role" )
columns......val roles = onetomany(RolesEntity) foreignkey("user_id") getter("roles") tostring (user => user.roles.map(rol => rol.toString))
def constructor(implicit m: ValuesMap) = {val rls: Traversable[Role] = m(roles).map(roleStr => Role.role(roleStr.value))new User(email = email, password = password, facebook_id = facebookId, created = created, roles = rls.toSet)Obviously this can never truly be lazy because I'm explicitly calling the roles relation and building it before constructing the User obj.
I tried to achieve this by creating a custom type Role and got stuck because of the Set[Role].oneToMany requires an entity...So then I tried creating my own RoleEntity - in the same way Double/String/Float/etc Entity is made.
But that didn't turn out well either. no matter what I tried I always ended up with this compilation error:[error] found : Set[models.Role][error] required: Traversable[persistence.mapperdao.RoleValue][error] val roles = onetomany(RoleEntity.oneToMany("users_roles","role")) foreignkey("user_id") getter("roles") to (_.roles <-----)
I noticed you showed a way to achieve lazyness by having a function in the domain class instead of a simple val, but I didn't like it for the exact same reasons you wrote down after the example.
Any idea how I can achieve this?
I tried this but it doesn't help in this problem.Role is not an entity with a table that has an id and is saved in the db.it's more like an Enum, only it's name is saved.
The problem is similiar tohttps://code.google.com/p/mapperdao/wiki/Enumerations
But trying to persist a Set[Gender] and not just one Gender.It makes more sense when speaking on something else than Gender :-)
Your enum in the example does not have it's own table in the db, it functions only to encapsulate some string info ("F"/"M") and giving it context of a Female/Male.
On Monday, April 22, 2013 7:34:59 PM UTC+2, samzil...@gmail.com wrote:Hi again,I just bumped into a pretty trivial scenario, which I have only found a somewhat complicated solution for.Perhaps you know of a simple one?
Scenario:case class User has a set of Emails (String).Or to make it a little more complicated, a set of "Role" - a case class that is persisted to db by its name (kinda like a java enum persistence), but doesn't need a db table of its own because it's hard-coded.The db holds a "users" table matching the UserEntity and a "users_roles" join table with user_id, role_name.
The somewhat complex solution:The only solution I found so far is to create an Entity for the join table - UsersRolesEntity.Then using this entity and a onetomany to construct the User case class with the correct simple Role objects.This solution is the same even for a simple Set[Emails] - to build the User case class one needs to extract the emails Set[String] from the given Set[UsersEmailsEntity].
Is there a simpler way to accomplish this?
Thanks,Sam
--
val gender = column("gender") to (customer => Gender.toString(customer.gender))
...
def constructor(implicit m) = {
val g = Gender.fromString(m(gender))
--