[Flow] Doctrine UniqueConstraints

Mark Kuiphuis typo3 at markyourweb.com
Mon Feb 17 08:48:12 CET 2014


Hi all,

I have a model "PaymentMethod" where I store all payment methods of a 
member.

I would like to prevent having multiple payment methods of the same type 
(Credit Card, Bank Transfer, Invoice) so I thought I would create a 
constraint on two properties of the PaymentMethod model. So far so good.

The constraint looks like:

@ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="paymentMethod", columns={"member","paymentType"})})

After a ./flow doctrine:update the index has been created nicely.

But how can I "catch" the situation where someone using the system is 
trying to add another paymentMethod of type "Invoice" to this member?
An exception is thrown, but I'd rather set a FlashMessage and redirect 
them to a page which displays the error?

I tried a try/catch block inside the 
createAction(\..\..\..\..\PaymentMethod $paymentMethod) { }
but this doesn't seem to work as persisting only occurs after the redirect.

Is there any nice solution for this by using DB constraints or should I 
implement everything in the logic inside the Controller action?

Kind regards,

Mark Kuiphuis


More information about the Flow mailing list