"Unique Together" behavior / how to prevent duplicates in child table

Is there a way to make a field in a child table unique but only for that parent? On another note, is there a “Unique Together” functionality available through the UI? (Could make ‘parent’ and ‘child_field’ unique together to achieve unique only for parent behavior).

Use case is a table acting as the “through” field for many-to-many functionality to describe items that are functionally equivalent to other items. I need the child table to only have one entry per item code, but only for that parent.

I think this kind of functionality is already there with respect to item table in the Item Variant.

So if I make a Template for Shirt with 2 variants as Size with options “Large” and “Small” and the other variant as color “Red” and “White”

Then I would only be able to create 4 variants in total and no duplication can be possible, I think it would be better if you could explain the use case a little better.

In our industry, many different manufacturers make functionally equivalent parts, so we need to keep track of “cross-references”. Variants don’t work for this use case, unfortunately.

I know that I can create “unique-together” constraints at the database level, I just wasn’t sure if this was available at the UI level.

1 Like