If this is really the best way (I suppose it is), what is the best way to map this to the DB? Would it be better to save the type column and then set it to one or the other?
, " " . DRY.
, , Student Provider , . , , , OO.
, , - "UserType" User. , . , , , Homework, StudentID, .
- , , - , , , Student Provider, Scala.
Lift -:
O-R .
class WikiEntry extends KeyedMapper[Long, WikiEntry] {
def getSingleton = WikiEntry
def primaryKeyField = id
object id extends MappedLongIndex(this)
object name extends MappedString(this, 32) {
override def dbIndexed_? = true
}
object owner extends MappedLongForeignKey(this, User)
object entry extends MappedTextarea(this, 8192) {
override def textareaRows = 10
override def textareaCols = 50
}
}
.
:
Scala:
trait Posting[MyType <: Mapper[MyType]] {
self: MyType =>
def primaryKeyField = id
object id extends MappedLongIndex(this)
object creator extends MappedLongForeignKey(this, User)
object createdAt extends MappedLong(this) {
override def defaultValue = System.currentTimeMillis
}
}
class FooPosting extends KeyedMapper[FooPosting] with Posting[MyType]