Jak mogę potraktować wiele tabel polimorficznie tzn chcę usunąć jeden rekord o danym id z podanej w stringu tabeli?
Próbowałem aby tabela implementowała np a potem rzutować w for
trait Idable {
def id: Column[Int]
}
albo rzutować w for na typ strukturalny
type TableWithId = {
def id: Column[Int]
}
Niestety żadne z podejść nie działa.
Albo zamiast usunięcia, wyświetlenie całego rekordu.
Mam metodę
def getTableByName(s: String): TableQuery[_] = s.toLowerCase match {
case "titles" => titles
case "subjects" => subjects
case "teachers" => teachers
case "courseTypes" => courseTypes
case "courses" => courses
case "users" => users
case "messages" => messages
}
i chcę to wykorzystać np tak
def delete(table: String, id: Int) = AdminAction {
implicit request =>
execute { implicit session =>
val q = for (t <- getTableByName(table) if t.asInstanceOf[Idable].id === id) yield t
q.delete
}
A może to miejsce na użycie Plain SQL? Tylko wtedy będę musiał zabezpieczyć się przed SQL Injection.