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?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With