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

**URL:** https://discuss.tryton.org/t/one2many-enforce-at-least-one-in-the-many-side-a-1-1-n-b/6845
**Category:** Developer
**Created:** [January 5, 2024, 3:04pm UTC](https://discuss.tryton.org/t/one2many-enforce-at-least-one-in-the-many-side-a-1-1-n-b/6845 "2024-01-05T15:04:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fgui](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/fgui/32/184_2.png) [@fgui](https://discuss.tryton.org/u/fgui)
#### Post date: [January 5, 2024, 3:04pm UTC](https://discuss.tryton.org/t/one2many-enforce-at-least-one-in-the-many-side-a-1-1-n-b/6845/1 "2024-01-05T15:04:04Z")

</div>

`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?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 5, 2024, 7:17pm UTC](https://discuss.tryton.org/t/one2many-enforce-at-least-one-in-the-many-side-a-1-1-n-b/6845/2 "2024-01-05T19:17:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [January 7, 2024, 2:20pm UTC](https://discuss.tryton.org/t/one2many-enforce-at-least-one-in-the-many-side-a-1-1-n-b/6845/3 "2024-01-07T14:20:11Z")

</div>

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