0

I have a model as shown below.

case class House (
    id: Int,
    name: String,
    cityId: Int,
    leaseInterval: Interval
)

case class Interval(start: ZonedDateTime, end: ZonedDateTime)

My table is defined as shown below.

CREATE TABLE houses(
  id INT AUTO_INCREMENT NOT NULL PRIMARY KEY ,
  name VARCHAR(255),
  city_id INT NOT NULL,
  start_at datetime DEFAULT NULL,
  end_at datetime DEFAULT NULL,
);

I am trying to write a method that saves a house in MySQL database as shown below.

val c = House.column
val id = sql"insert into ${House.table} (${c.name}, ${c.cityId}, ${c.startAt}, ${c.endAt}) values (${name}, ${cityId}, ${startAt}, ${endAt})".stripMargin.updateAndReturnGeneratedKey.apply()

But I get the following compilation error.

House#startAt not found. Expected fields are #id, #name, #cityId, #leaseInterval.

I get the same error for c.endAt column too.

Am I doing something wrong? The error goes away if I use c.column("start_at").

Kakaji
  • 1,421
  • 2
  • 15
  • 23

1 Answers1

0

Seems like the missmatch between your house class and house table might be the cause of it. you need the columns from Interval as well or put startAt and endAt in your House class.

larstoc
  • 55
  • 1
  • 9