I think this table should become empty before adding new data? so I do this:
$emails = $em->getRepository('Entities\BannedEmail')->findAll();
foreach ($emails as $email) {
$deletBanned = $em->remove($email);
}
$em->flush();
if (!empty($_POST['bannedEmails'])) {
$emails = @explode("\n", $_POST['bannedEmails']);
foreach ($emails as $email) {
$banned = new Entities\BannedEmail($email);
$em->persist($banned);
}
}
$em->flush();
And also noticed I should flush after removing and after adding to prevent
duplicate entry exception. any suggestion to improve this?
On Sat, Apr 19, 2014 at 1:56 PM, Herman Peeren <[email protected]>wrote:
> On Saturday, 19 April 2014 11:09:20 UTC+2, Parsifal wrote:
>>
>> am I correct that I should instantiate the entity and persist it inside
>> loop and flush it when loop finished?
>>
>
> Yes.
>
> But: look out with what is allready in database.
> And: maybe you should rethink this model, for it probably could be
> improved.
>
> --
> You received this message because you are subscribed to the Google Groups
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.