views:

38

answers:

1

Hi!

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.

Thanks in advance for the help, Best regards!

A: 

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
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
Doctrine will throw an exception that you can handle with a try-catch block.
Maerlyn