This topic contains 2 replies, has 1 voice, and was last updated by jakabadambalazs 9 years, 4 months ago.
- Topic
I have two bundles: Account and Contact and I am playing around with e-mails. Since I wanted to create an entity which would hold e-mails for both Accounts and Contacts, in AccountBundle I have created this entity:
<?php
namespace Mekit\Bundle\AccountBundle\Entity;use Doctrine\ORM\Mapping as ORM;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
use Oro\Bundle\AddressBundle\Entity\AbstractEmail;
use Oro\Bundle\EmailBundle\Entity\EmailInterface;use Mekit\Bundle\ContactBundle\Entity\Contact;
/**
* @ORM\Entity
* @ORM\Table("mekit_account_email", indexes={
* @ORM\Index(name="primary_email_idx", columns={"email", "is_primary"})
* })
* @Config(
* defaultValues={
* "entity"={
* "icon"="icon-envelope"
* },
* "note"={
* "immutable"=true
* },
* "activity"={
* "immutable"=true
* },
* "attachment"={
* "immutable"=true
* }
* }
* )
*/
class AccountEmail extends AbstractEmail implements EmailInterface {
/**
* @ORM\ManyToOne(targetEntity="Mekit\Bundle\AccountBundle\Entity\Account", inversedBy="emails")
* @ORM\JoinColumn(name="account_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
protected $ownerAccount;/**
* @ORM\ManyToOne(targetEntity="Mekit\Bundle\ContactBundle\Entity\Contact", inversedBy="emails")
* @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
protected $ownerContact;/**
* @return Account
*/
public function getOwnerAccount() {
return $this->ownerAccount;
}/**
* @param Account $ownerAccount
* @return $this
*/
public function setOwnerAccount(Account $ownerAccount = null) {
$this->ownerAccount = $ownerAccount;
return $this;
}/**
* @return bool
*/
public function isAccountEMail() {
return (!is_null($this->ownerAccount));
}/**
* @return Contact
*/
public function getOwnerContact() {
return $this->ownerContact;
}/**
* @param Contact $ownerContact
* @return $this
*/
public function setOwnerContact(Contact $ownerContact = null) {
$this->ownerContact = $ownerContact;
return $this;
}/**
* @return bool
*/
public function isContactEmail() {
return (!is_null($this->ownerContact));
}/**
* Returns entity which owns this Email
* @return Account|Contact|null
*/
public function getEmailOwner() {
if($this->isAccountEMail()) {
return $this->getOwnerAccount();
} else if ($this->isContactEmail()) {
return $this->getOwnerContact();
}
return null;
}/**
* {@inheritdoc}
*/
public function getEmailField() {
return 'email';
}
}… and in both Mekit\Bundle\AccountBundle\Entity\Account and Mekit\Bundle\ContactBundle\Entity\Contact I have created the “emails” property creating the necessary relationships.
It seemed like a good idea because now I have emails stored in the same table.
Everything works apart from when I try to delete a Contact through the rest api controller which says:
<b>Notice</b>: Undefined index: owner in <b>/home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php</b> on line <b>1753</b><br />
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php</b> on line <b>1758</b><br />
{"status":"error","status_code":500,"status_text":"Internal Server Error","current_content":"","message":"Unrecognized field: primary"}and it is right becuase i renamed the owner fieled to $ownerAccount and $ownerContact.
Actually removing Accounts (event with e-mails) works correctly.
Do you recon I can fix this somehow?
I think the answer should be somehere in the ‘EmailOwnerProviderStorage::getEmailOwnerFieldName’ / ‘EmailOwnerProviderStorage::getEmailOwnerColumnName’ but I cannot figure out how to do this.hmmm, or maybe it has not to do with Emails???
oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.