Skip to content

Conversation

@nsams
Copy link
Contributor

@nsams nsams commented Nov 13, 2025

Metadata for this field is nullable=true

  @ManyToOne({ entity: () => Country, ref: true, cascade: [Cascade.REMOVE] })
  country!: Ref<Country>;

Workaround, explicitly set to false:

  @ManyToOne({ entity: () => Country, ref: true, cascade: [Cascade.REMOVE], nullable: false })
  country!: Ref<Country>;

See test in this PR for reproduction

@B4nan
Copy link
Member

B4nan commented Nov 13, 2025

I honestly don't remember why it is like that, the code is super old.

https://github.com/mikro-orm/mikro-orm/blob/master/packages/core/src/metadata/MetadataDiscovery.ts#L491

I'll change it in v7, since it might be seen as breaking.


Anyway, do you understand what the cascade option is for? In your test case, it means that if you remove the owning entity, the target relation will get removed as well. People usually want the opposite direction, which is deleteRule: 'cascade'.

@nsams
Copy link
Contributor Author

nsams commented Nov 13, 2025

Thank you!


(I'm not the developer writing this relation code, but I'll forward your comment - makes perfectly sense - thank you)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants