user1954544
user1954544

Reputation: 1687

Symfony2, Doctrine, Updation OneToMany entries

i have function

private function updateCharacters($oApiKeyInfo) // argument is base entity
{
    $aXmlCharacter = $this->fXml->getXmlRowset($this->oXml, 'row');
    // insert new
    foreach ($aXmlCharacter as $oXmlCharacter)
    {
        $loopData = $this->fXml->getXmlAttributesAsArray($oXmlCharacter);

        $oApiKeyInfoCharacters = new apiKeyInfoCharacters();

        $oApiKeyInfoCharacters
                ->setKeyID($this->keyID)
                ->setCharacterID($loopData['characterID'])
                ->setCharacterName($loopData['characterName'])
                ->setCorporationID($loopData['corporationID'])
                ->setCorporationName($loopData['corporationName'])
                ->set_apiKeyInfo_byKeyID($oApiKeyInfo);


        $this->em->persist($oApiKeyInfoCharacters);
    }

// $this->em->flush() is in main (public) function
}

but, it creates dublicates... and i want that in db was ONLY that entries that is in $aXmlCharacter (array), others must be deleted

now code above is only adding new entries, but i need remove previous

can someone help to deal with it? and please show working examples

Upvotes: 0

Views: 67

Answers (1)

Fusselchen
Fusselchen

Reputation: 382

Dublicate entries i can not see any definition for uniquenes.
Deleting an Object vom database is simple as the documentation shows.

$product = $em->getRepository('YourBundle::apiKeyInfoCharacters')->find($id);
$em->remove($product);
$em->flush();

But why do you want to delete the existing one instead of updating?

Upvotes: 1

Related Questions