One2many enforce at least one (in the many side) A[1]-<>- [1..n]B

A [1] -<>- [1..n] B

I would like to enforce that there can never be an A with at least one B.
I use validate to enforce creation and update of A with at least one B.
I try to use delete of B to enforce that I cannot delete the last B (of an A) but it backfire because now I cannot delete any A. I want to be able to delete A (cascade B).

How can I enforce that there is never an A with O Bs?

Only SQL constraint can really ensure such kind of constraint but unfortunately there is no such SQL constraint.

But you can make the One2Many required and trigger the validation of the related A record when B records are deleted but only for A records that are not going to be deleted.
So it is very complex to enforce so you better have to rethink your design so it can be correctly set in relational database.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.