/**
* adds an address to the entity.
*
* @param Account $account The entity to add the address to
* @param AddressEntity $address The address to be added
* @param Bool $isMain Defines if the address is the main Address of the contact
*
* @return AccountAddressEntity
*
* @throws \Exception
*/
public function addAddress($account, AddressEntity $address, $isMain = false)
{
if (!$account || !$address) {
throw new \Exception('Account and Address cannot be null');
}
$accountAddress = new AccountAddressEntity();
$accountAddress->setAccount($account);
$accountAddress->setAddress($address);
if ($isMain) {
$this->unsetMain($account->getAccountAddresses());
}
$accountAddress->setMain($isMain);
$account->addAccountAddress($accountAddress);
$address->addAccountAddress($accountAddress);
$this->em->persist($accountAddress);
return $accountAddress;
}