Created
January 8, 2013 19:41
-
-
Save aaronlifton3/4487214 to your computer and use it in GitHub Desktop.
Post model for Play 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package models | |
| import play.api.Play.current | |
| import java.util.Date | |
| import com.novus.salat._ | |
| import com.novus.salat.annotations._ | |
| import com.novus.salat.dao._ | |
| import com.mongodb.casbah.Imports._ | |
| import se.radley.plugin.salat._ | |
| import mongoContext._ | |
| case class Post( | |
| id: ObjectId = new ObjectId, | |
| name: String, | |
| description: String, | |
| @Key("group_id")group: Option[ObjectId] = None, | |
| created: Date = new Date(), | |
| updated: Option[Date] = None | |
| ) { | |
| override def toString = "%s - %s".format(id, name) | |
| override def toSlug = { | |
| val Slugger = """[\./]\?:[^/?#\.]+\?""".r | |
| name match { | |
| case Slugger(c) => "slug: " + c | |
| case _ => "slug none" | |
| } | |
| } | |
| } | |
| object Post extends ModelCompanion[Post, ObjectId] { | |
| val dao = new SalatDAO[Post, ObjectId](collection = mongoCollection("posts")) {} | |
| def findOneByName(name: String): Option[Post] = dao.findOne(MongoDBObject("name" -> name)) | |
| def findByGroup(group: String) = dao.find(MongoDBObject.empty) //.toList | |
| def findGroup(id: Option[ObjectId]): Option[Group] = Group.findOneById(id.get) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment