I am using Slick to connect to a PostgresDB
I have defined three tables:
Brand, Category, Item
case class Category(categoryId: UUID,name:String)
case class Brand(id:UUID, name: String)
case class Item(
id: UUID,
name: String,
description: String,
price: BigDecimal,
brand: Brand,
category: Category
)
Below are the mappings for slick tables
class BrandTable(tag: Tag) extends Table[Brand](tag, Some("shopping"), "Brand") {
def id: Rep[UUID] = column[UUID]("id", O.PrimaryKey, O.Unique)
def name: Rep[String] = column[String]("name", O.Unique)
override def * : ProvenShape[Brand] = (id, name) <> (Brand.tupled, Brand.unapply)
}
class CategoryTable(tag:Tag) extends Table[Category](tag, Some("shopping"), "Category"){
def id = column[UUID]("id", O.PrimaryKey, O.Unique)
def name = column[String]("name",O.Unique)
override def * : ProvenShape[Category] = (id, name) <>(Category.tupled, Category.unapply)
}
class ItemTable(tag: Tag) extends Table[Item](tag, Some("shopping"), "Items") {
implicit val uuidColumnType: BaseColumnType[UUID] = MappedColumnType.base[UUID, String](
_.toString,
UUID.fromString
)
def id = column[UUID]("id", O.PrimaryKey, O.Unique)
def name = column[String]("name")
def description = column[String]("description")
def price = column[BigDecimal]("price")
def brandId = column[UUID]("brand_id")
def categoryId = column[UUID]("category_id")
//Mapping to Brand Table
def brand: ForeignKeyQuery[BrandTable, Brand] =
foreignKey("brand_fk", brandId, SlickTables.brandTable)(_.id)
def category: ForeignKeyQuery[CategoryTable, Category] =
foreignKey("category_fk", categoryId, SlickTables.categoryTable)(_.id)
override def * : ProvenShape[Item] =
(id, name, description, price, brand, category) <> ( Item.tupled, Item.unapply)
}
BrandTable and CategoryTable are working as expected.
But I am seeing issues with ItemTable when I try to define the foreign key
override def \* : ProvenShape\[Item\] =
(id, name, description, price, brand, category) \<\> ( Item.tupled, Item.unapply)
throws compile error:
value <> is not a member of (slick.lifted.Rep[java.util.UUID], slick.lifted.Rep[String], slick.lifted.Rep[String], slick.lifted.Rep[BigDecimal], slick.lifted.ForeignKeyQuery[tables.BrandTable,model.Brand], slick.lifted.ForeignKeyQuery[tables.CategoryTable,model.Category])
(id, name, description, price, brand, category) <> (Item.tupled, Item.unapply _)
I have the import slick.jdbc.PostgresProfile.api._ added <> should work
I am not sure why I am seeing this error
Can some please suggest.