Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance in Lift Mapper or Record Framework

Is there a way to define proper a inheritance model in Lift using Mapper o Record Framework where there is a table for the parent class and one table for each son?

like image 343
Javier Avatar asked Sep 01 '10 21:09

Javier


1 Answers

Assuming you want to use inheritance to be able to use the same mapped fields in each of the subclasses, I've approached this by using a trait for those fields:

trait SuperFields[T <: Mapper[T]] {
  self: T =>
  object DESCRIPTION extends MappedString[T](this, 255)
  object BRAND extends MappedString[T](this, 50)
  // etc
}

Then each Mapper/MetaMapper will extend SuperFields, but define their own database table and connection identifiers:

class Product extends Mapper[Product] with SuperFields[Product] {
  override def getSingleton = Product
}

object Product extends Product with MetaMapper[Product] {
  override def dbTableName = "PRODUCT"
  override def dbDefaultConnectionIdentifier = SomeConnection
}

And:

class Service extends Mapper[Service] with SuperFields[Service] {
  override def getSingleton = Service
}

object Service extends Service with MetaMapper[Service] {
  override def dbTableName = "SERVICE"
  override def dbDefaultConnectionIdentifier = SomeOtherConnection
}
like image 125
Collin Avatar answered Oct 29 '22 02:10

Collin