Skip to content

Instantly share code, notes, and snippets.

@gakuzzzz
Created May 8, 2011 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gakuzzzz/961416 to your computer and use it in GitHub Desktop.
Save gakuzzzz/961416 to your computer and use it in GitHub Desktop.
anormの拡張
import play.db.anorm._
import play.db.anorm.defaults._
trait Identifiable[A] {
type ID = A
val id: Pk[ID]
}
trait ExMagic[A <: Identifiable[_]] extends Magic[A] {
def findById(id: A#ID): Option[A] = find("id = {id}").onParams(id).first()
def findAll: Seq[A] = find().list()
def delete(v: A): Boolean = deleteById(v.id())
def deleteById(id: A#ID): Boolean = super.delete("id = {id}").onParams(id).execute()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment