I’ve looked into a couple of posts, but couldn’t find a working solution.
My question is beyond simple:
I have an entity with say id, url and title. The URL should be unique (in MySQL PDO). I’ve managed to create both the entity and schema with no problems. Now when I walk some records I call persist() on each, and finaly a flush(). The problem is that when I try to insert duplicate entries for the URL it gives me an exception. How to supress it?
When a duplicate entry is being inserted it should just skip it and insert the rest. No need for events, ON UPDATE statements, triggers and all that fancy stuff.
I’ve tried catching any exceptions thrown by persist or flush(), but can’t really seem to do it correctly.
Any ideas are welcome, thank you!
EDIT: Found my solution in here: Symfony2 Controller won't catch exception
A better approach would be to specify a validation contstraint to avoid having to deal with this exception. In yaml (taken from the symfony docs)