2

I'm using an embedded relation to allow the user to edit/add books to a library and in the same form to add/remove n authors who wrote the book within the auto generated admin.

Here is my problem: An authors name is unique, so when I enter an author that already exists the sfValidatorDoctrineUnique produces the error.

An object with the same "name" already exist.

What I want to do is catch this error and tell the form not to try to add the exisiting author anew.

Do I use the event system for that, or modify the validators or how can I do that?

thank you very much hoodie

PS: after some searching I found something that might be a solution but I haven't made it work yet http://symfonyguide.wordpress.com/2009/09/28/symfony-forms-saving-process/

hoodie
  • 193
  • 5
  • For the future readers - I don't think that this error message above, that OP mentioned, was actually about duplicated data, but really an error message about the duplicated TABLE, which is generated by Doctrine when doing the DB structure check, for example with: `php bin/console doctrine:schema:update --dump-sql`. I was also getting it when dealing with Many-to-many relations, in actual many-to-many setup (and not through multiple one-to-many) – userfuser Feb 07 '17 at 08:53

1 Answers1

0

I my opinion you should not to add new author if it already exists.

sfDoctrineActAsTaggablePlugin do the same way. It searches for an existing tags and merge them with current (added by user from form) tags.

But here is one issue: Two authors - Aleksander Pushkin and Alexander Pushkin, is it same authors for us, but different for machine.

cuhuak
  • 498
  • 4
  • 9
  • I probably phrased the question wrong. I don't want to add a new author with the name of another. I want the system to recognize, that the author the admin added to the book already exists and not try to recreated it but just link it to the new book. – hoodie Feb 24 '11 at 13:38