The index ensure only that the Documents don't get duplicated.
If you want to do the equivalent of a "REPLACE INTO", you should either:
Get the document if present, then set the values:
$keyword= $dm->findBy(array("name"=> $name, "lang"=> $lang));
if(!$keyword) {
$keyword= new Keyword();
$dm->persist($keyword);
}
$keyword->setCreateDate(new \DateTime());
$keyword->setLang("fr");
$keyword->setLastParseDate(new \DateTime());
$keyword->setName("test");
This will lead to 2 queries.
Or:
Do an upsert:
$dm->createQueryBuilder('Keyword')
->setNewObj(array(
'lang' => 'fr',
'name' => 'test',
// ... other fields
))
->field('lang')->equals('fr')
->field('name')->equals('test')
->getQuery()
->execute();
This will update the doc if present, otherwise it will create a new Document.
However, the new document is created from the raw array, actually bypassing all the Doctrine events (like the @Timestampeble annotation).
So if the extra query isn't a problem, use the first method.