Let's say I have an entity Company with a one-to-many relationship with entity Employee. I want to query for a company which would typically be done via:
return companyRepo.findOne(companyId, { relations: ["employees"]})
The above query will cause OOM issues, and a more efficient approach (approach number 2) is to do the following:
const company = await companyRepo.findOne(companyId);
const employees = await employeeRepo.find({ where: { companyId });
company.employees = employees;
return company;
Everything works except when I try to save (companyRepo.save(company)), when I try to save I get the following error:
Error: null value in column "company_id" of relation "employee" violates not-null constraint
Why is this happening, how can I get approach number 2 to work?