Similar to the inquiry posted by this user, I am facing a challenge while trying to persist an entity named Project
along with its associated Spaces
through a One-to-Many relationship using TypeORM. Although the SQL logging output indicates a successful commit:
query: START TRANSACTION
query: INSERT INTO "project_model"(...) VALUES (...) RETURNING "dateCreated", "dateModified"
query: UPDATE "space_model" SET "projectId" = ... WHERE "id" = ...
query: COMMIT
I cannot find the data in the Spaces
table when checking Postgres.
Here are the two models involved:
@Entity()
class Project extends IProject {
@OneToMany(type => Space, space => space.project)
public spaces: Space[]
}
@Entity()
class Space extends ISpace {
@ManyToOne(type => Project, (project) => project.spaces, {
cascade: true
})
project: Project
}
In addition, here is the simplified repository method responsible for saving:
async updateData(data: Partial<T>): Promise<T> {
await this.getRepo();
const dbObj = data as any;
console.log(dbObj);
const updated = await this.repo.save(dbObj);
return updated;
}
What could be causing this issue?