Doctrine hook to validate record references onInsert

318 Views Asked by At

I want to add Product if and only if it has say at least two Variants (Product can have many Variants).

How to validatate this in doctrine's preInsert or postInsert hook and stop transaction if there are not enough Variants? I know how to check scalar field using $event->getModified() or $event->data, but wondering if it is possible with whole relations especially if record has not been inserted to database yet. I mean both Many to Many and One to Many relations.

1

There are 1 best solutions below

0
On

there are special hooks for validation that you can use to easily implement this functionality: validate(), validateOnInsert() and validateOnUpdate()