I am using Ktorm and trying to create an abstract and generic DAO for my tables. In the end I get a type mismatch though and I don't see where I am wrong:
BaseEntity is an interface for an entity class with an id:
interface BaseEntity<T: Entity<T>>: Entity<T> {
val id: Int
}
User (the ORM class):
interface User: BaseEntity<User>
IdTable (a table that has an int id as primary key):
open class IdTable<T : BaseEntity<T>>(tableName: String) : Table<T>(tableName) {
val id = int("id").primaryKey().bindTo { it.id }
}
Users (SQL table):
object Users : IdTable<User>("users")
BaseDao:
open class BaseDao<E : BaseEntity<E>>(private val es: EntitySequence<E, IdTable<E>>)
UserDao implements the BaseDao:
class UserDao(val es: EntitySequence<User, IdTable<User>>) : BaseDao<User>(es)
Now as mentioned in the Ktorm docs I create an EntitySequence like
val Database.users get() = this.sequenceOf(Users)
and I want to create a UserDao:
userDao = UserDao(database.users)
But I get
Type mismatch.
Required:
EntitySequence<User, IdTable<User>>
Found:
EntitySequence<User, Users>
But Users
is of type IdTable<User>
as it inherits from it. Why does the compiler not know that?