Hi All,
Although the below code works after repeating it for various types of users such as APIUser, SystemUser etc.
object APIUser extends ModelCompanion[APIUser, ObjectId]{......}
object SystemUser extends ModelCompanion[SystemUser, ObjectId]{......}
Any thoughts on how to make it generic enough so that byId and other methods (common for all types of users) can be placed in one trait and used by all other user types?
Thanks
Pawan
------
@Salat
sealed trait User{
def id: ObjectId
def fullName: String
def email: String
}
case class APIUser(@Key("_id") id:ObjectId = new ObjectId, fullName:String, email:String,createdOn:DateTime = DateTime.now) extends User
object APIUser extends ModelCompanion[APIUser, ObjectId]{
com.mongodb.casbah.commons.conversions.scala.RegisterConversionHelpers()
com.mongodb.casbah.commons.conversions.scala.RegisterJodaTimeConversionHelpers()
val mongocollection = MongoConnection()("db")("collection")
val dao = new SalatDAO[APIUser, ObjectId](collection = mongocollection) {}
def byId(id: String): Option[APIUser] = dao.findOne(MongoDBObject("_id" -> new ObjectId(id)))
}