I have a simple Parent
object:
case class ParentCreate(name: String, age: Int, kids: Seq[String])
Now, in the database I have 2 tables to represent this, perent & kid, cause a parent can have many kids, and in the kid table I have a forein key to parentId.
the creation of the tables looks like this:
CREATE TABLE Parent (
parentId int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
age int NOT NULL,
PRIMARY KEY (parentId)
);
CREATE TABLE Kid (
kidId int NOT NULL AUTO_INCREMENT,
name: varchar(255) NOT NULL,
parentId int NOT NULL,
PRIMARY KEY (kidId),
FOREIGN KEY (parentId) REFERENCES Parent(parentId)
);
So now when I get a request of ParentCreate
object, I need to have another layer of case classes that will represent the database structure, so I need to transform ParentCreate
object to Parent
and Kid
objects:
Parent(name: String, age: Int)
Kid(name: String)
cause this is how the data is modeled in the database.
my issue is the I get a ParentCreate
request that still dont have parentId, and to insert the kids I need the kids parentId...
How this is done the best way with quill?
appreciate any help :)