All Downloads are FREE. Search and download functionalities are using the official Maven repository.

elab.scala-activerecord_2.11.0.3.2.source-code.STISupport.scala Maven / Gradle / Ivy

There is a newer version: 0.5.1
Show newest version
package com.github.aselab.activerecord

import scala.reflect.classTag
import com.github.aselab.activerecord.dsl._

/**
 * Single Table Inheritance
 */
trait STI { self: ActiveRecordBase[_] =>
  @Column("type") val _type = this.getClass.getSimpleName
}

trait STISupport[T <: ActiveRecord with STI] { self: ActiveRecordBaseCompanion[Long, T] =>
  private[this] lazy val _typeName = classTag[T].runtimeClass.getSimpleName

  override def defaultScope = queryToRelation[T](table).where(_._type === _typeName)

  override def find(id: Long): Option[T] = defaultScope.find(id)

  override protected[activerecord] def delete(id: Long): Boolean =
    all.where(_.id === id).forceDestroyAll() > 0

  override def forceDeleteAll(): Int = all.forceDestroyAll()

  override def forceDelete(condition: T => LogicalBoolean): Int =
    all.where(condition).forceDestroyAll()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy