I am using Loopback 4 first time and using MySQL as DB connector. I am able to use models with all my code but faced issue for id columns with generated: true.
First using required: true in my models is not allowing to add data using API Calls.It giving me issue id can't be blank. I able to ignore this error if I made required: false That actually not a big issue as I expecting MySQL to generate value using AUTO INCREMENT.
But now I need to generate some fixture data using a single API. In that case, I need to manually insert data into id column something like
await this.projectRepository.create({
id: 1,
title: "My Project"
createdAt: (new Date).toISOString()
});
await this.projectItemsRepository.create({
id: 1,
projectId: 1,
title: "My Item 1"
createdAt: (new Date).toISOString()
});
await this.projectItemsRepository.create({
id: 2,
projectId: 1,
title: "My Item 2"
createdAt: (new Date).toISOString()
});
So Project Id is foreign key in projectitems model. Now if I execute this script, I am getting issue for id id can't be set. Look like loopback 4 blocking attempt to set value in case of id column is generated.