Vinicius Carvalho
03/01/2019, 8:41 PMobject Products : IdTable<Int>("products") {
override val id = integer("upc").primaryKey().entityId()
val sku = integer("sku")
val name = varchar("name", 255)
val price = float("price")
val type = varchar("type", 45)
val manufacturer = varchar("manufacturer", 45)
val description = text("description")
val model = varchar("model", 45)
val image = varchar("image", 255)
val lastUpdated = datetime("last_updated")
}
class Product(id: EntityID<Int>) : IntEntity(id){
companion object : EntityClass<Int, Product>(Products)
var upc by Products.id
var sku by Products.sku
var name by Products.name
var price by Products.price
var type by Products.type
var manufacturer by Products.manufacturer
var description by Products.description
var model by Products.model
var image by Products.image
var lastUpdated by Products.lastUpdated
var categories by Category via ProductCategories
}
object Categories : IdTable<Int>("category"){
override val id: Column<EntityID<Int>> = integer("id").primaryKey().entityId()
var name = varchar("name", 255)
}
class Category(id: EntityID<Int>) : IntEntity(id){
companion object : IntEntityClass<Category>(Categories)
var name by Categories.name
}
object ProductCategories : Table("products_category"){
val product = reference("product_id", Products.id).primaryKey(0)
val category = reference("category_id", Categories.id).primaryKey(1)
}