tjb
02/19/2019, 3:43 AMclass Post(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<Post>(Posts)
var title by Posts.title
var description by Posts.description
var wage by Posts.wage
var city by Posts.city
var state by Posts.state
var country by Posts.country
var employmentType by Posts.employmentType
var seniority by Posts.seniority
var tags by Tag via PostsTags
}
object Posts: IntIdTable() {
val title = varchar("title", 255)
val description = text("description")
val wage = decimal("wage", 15, 2)
val city = varchar("city", 255)
val state = varchar("state", 255)
val country = varchar("country", 255)
val employmentType = varchar("employment_type", 255)
val seniority = varchar("seniority", 255)
}
object PostsTags: Table("posts_tags") {
val post = reference("post", Posts).primaryKey(0)
val tag = reference("tag", Tags).primaryKey(1)
}
class Tag(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<Tag>(Tags)
var name by Tags.name
var version: String by Tags.version
var type by Tags.type
var posts by Post via PostsTags
}
object Tags: IntIdTable() {
val name = varchar("name", 255)
val version = varchar("version", 255)
val type = varchar("type", 255)
}
However when I do the following query i get an error
return transaction {
Posts
.selectAll()
.andWhere {
Posts.title like "%$query%"
}
.map {
it.toPost()
}
}
java.lang.IllegalStateException: Property klass should be initialized before get.
Are my models incorrect?