Lift mapper/meta mapper
author"Tomas Zeman <tzeman@volny.cz>"
Tue, 19 Oct 2010 10:04:05 +0200
changeset 3 d45ef9f0c1ae
parent 2 f1b6c7418cb8
child 4 5ef63a5d98b2
Lift mapper/meta mapper
scala/lift/model.scala
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scala/lift/model.scala	Tue Oct 19 10:04:05 2010 +0200
@@ -0,0 +1,58 @@
+/*
+ * Copyright ...
+ */
+package example
+
+import net.liftweb.common._
+import net.liftweb.mapper._
+
+/**
+ * Mixin into mapper
+ */
+trait Named { self: BaseMapper =>
+  object name extends MappedPoliteString[MapperType](
+    this.asInstanceOf[MapperType], 40) {
+
+    override def displayName = "Name"
+
+    import net.liftweb.util.Helpers._
+    override def toForm = super.toForm map { _ % ("class" -> "text") }
+  }
+}
+
+object Example extends Example with LongKeyedMetaMapper[Example]
+  with LongCRUDify[Example] {
+
+  override def dbTableName = "..."
+
+  override def validation = validateSomething _ :: super.validation
+
+  def validateSomething(v: Example): List[FieldError] = ...
+
+  override def afterSave = ...
+
+  override def fieldOrder = List(...)
+  override def fieldsForList = List(...)
+}
+
+class Example extends LongKeyedMapper[Example] with IdPK
+  with CreatedUpdated with Named with OneToMany[Long, Example] {
+
+  def getSingleton = Example
+
+  object children extends MappedOneToMany[Child](Child, Child.parent)
+    with Cascade[Child]
+
+  object stringField extends MappedString(this, 40)
+
+  object longField extends MappedLong(this)
+
+  object textField extends MappedTextarea(this, 4096) {
+    override def defaultValue = ""
+    override def setFilter = crop _ :: super.setFilter
+  }
+
+  override def formFields = List(..)
+}
+
+// vim: set ts=2 sw=2 et: