I have a question about inserting multiple entities. What happens to the entities if i persist every entity in a loop and then i flush ? I mean what happens if one of this entities is duplicated and can't be inserted ? Are all entities removed or only the one which is duplicated ?
foreach($datas as $data) {
$obj = new DataLerne();
// Code ..
$obj->setAtt($data['att']);
$em->persist($obj);
}
$em->flush();
Thank you for your responses
Since you are instantiating your object with the new
Operator, there technically can be no duplicate.
If you are concerned about duplicates in your array, which is filling the Objects Attribute, doctrine does not care about this.
For Doctrine those are as many new entities as iterations in your foreach loop and they all will be written to your database on flush.
But should there be any constraint standing in the way of inserting into the database, doctrine will throw an exception and abort where it stands.