Javier
Javier

Reputation: 61

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?

Upvotes: 6

Views: 745

Answers (1)

Collin
Collin

Reputation: 1451

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
}

Upvotes: 9

Related Questions