Doctrine NOOB here, trying to figure out how to prevent a duplicate record in an embed many property. I have a EmbededDocment like this:
<?
/**
* @EmbeddedDocument
*/
class Contact {
/**
* @Id
*/
private $id;
/**
* created timestamp
* @Date
*/
private $created;
/**
* modified timestamp
* @Date
*/
private $modified;
/**
* @String
*/
private $name;
/**
* @String
*/
private $name;
/**
* @String
*/
private $address;
}
what I want to happen is when I add a new contact, two contacts can have the same name, two contacts can have the same address, but two contacts can not have the same name and address. When checking for duplicates, doctrine will need to ignore the $id, $created and $modified properties as these will almost always be distinct. It is the combination of all the other fields that must be unique. How can this be accomplished using doctrine? Does this logic belong in a service layer or can doctrine do it for me?
UPDATE: I do accept that Andrew's answer is the correct way to check for duplication using Mongo, I really want to know if doctrine can do this for me. Therefore, I'm starting a bounty.
You could implement an event listener which will listen to an preUpdate and prePersist event. http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/reference/events.html
In your event, you can do your own check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With