0

Currently, I am developing an application which domain model should prevent objects duplication according the equality or not of some object fields.

So, I am thinking to handle this comparison on the save method of the class: if some existing object has some properties equal to the object to be saved, the save should be prevented.

I am thinking to deal this situation with an Exceptions, which would be thrown and catched in the action, in order to present a message to the user, if necessary. Unfortunately, my knowledge about Exceptions is not quite good and more: would be this solution the most adequate?

The ORM which I am using is Doctrine.

Rui Gonçalves
  • 2,423
  • 6
  • 30
  • 42

1 Answers1

0

Why don't you create an unique index on multiple columns in your schema: This is an example taken from Doctrine's manual:

MultipleIndexTest:
  columns:
    name: string
    code: string
    age: integer
  indexes:
    myindex:
      fields:
        name:
          sorting: ASC
          length: 10
        code: -
      type: unique
Maerlyn
  • 33,687
  • 18
  • 94
  • 85
  • Hi! Honestly, I do not considered the approach you mentioned, but it seems also valid. I only have one doubt: how can I set proper messages to the user, with the solution you suggested, it is not necessary to handle with the controller and view? – Rui Gonçalves Oct 13 '10 at 10:45
  • Doctrine will throw an exception that you can handle with a try-catch block. – Maerlyn Oct 13 '10 at 18:34