RobinCK / typeorm-fixtures

:pill: Fixtures loader for typeorm 🇺🇦
https://robinck.github.io/typeorm-fixtures/
MIT License
566 stars 45 forks source link

[Bug] Null ID when referencing another fixture #202

Open tylergets opened 2 years ago

tylergets commented 2 years ago

Hey there, I am having issues with the latest version of this library.

When I try and create a new instance of a child model, it is not receiving the ID of the referenced fixture. This results in the entity failing to save because of constraints.

For example:

error: Error: null value in column "locationId" violates not-null constraint

Here are my fixtures

entity: Location
items:
  location1:
    name: '{{company.name}}'
    tenant: 'd1a5fcf3-08f6-4035-a766-6c7c9733c39a'
    flags: '[]'

and

entity: Role
items:
  role1:
    name: '{{company.name}}'
    location: '@location1'

In this scenario, location is defined as a ManyToOne lazy relationship on Role. Tenat is also a ManyToOne which I hardcoded and works as expected.

Postgres returns this error

 messageDetail: 'Failing row contains (d353769e-e96d-447d-8773-0637028b6f86, Romaguera, Will and Hettinger, romaguera-will-and-hettinger, f, f, f, f, {}, null, null, t, #689F38, null, null, null, f, blank, $ID$).',

I am continuing to look further, however wanted to see if anyone else has ran into this.

Software Version(s)
typeorm-fixtures 3.0.1
tylergets commented 2 years ago

Further testing reveals that this is probably related to lazy relationships, PR #198 fixes the issue