This topic contains 3 replies, has 2 voices, and was last updated by Mike Kudelya 7 years, 5 months ago.
- Topic
Hello guys, I’m trying to add an inverse relation to a many to one relation. This is my custom class:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314<?phpnamespace Biotay\Bundle\AccountBundle\Entity;use Doctrine\ORM\Mapping as ORM;use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;use OroB2B\Bundle\AccountBundle\Entity\Account;/*** Balance** @ORM\Table(name="biotay_account_balance")* @ORM\Entity* @Config()*/class Balance{/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @var Account* @ORM\ManyToOne(targetEntity="OroB2B\Bundle\AccountBundle\Entity\Account")*/private $account;/*** @var string** @ORM\Column(name="reference_code", type="string", length=255)*/private $referenceCode;/*** @var \DateTime** @ORM\Column(name="document_date", type="date")*/private $documentDate;/*** @var string** @ORM\Column(name="document_number", type="string", length=255)*/private $documentNumber;/*** @var string** @ORM\Column(name="document_type", type="string", length=255)*/private $documentType;/*** @var \DateTime** @ORM\Column(name="debt_expire_date", type="date")*/private $debtExpireDate;/*** @var string** @ORM\Column(name="ars_amount", type="decimal", precision=10, scale=2)*/private $arsAmount;/*** @var string** @ORM\Column(name="usd_amount", type="decimal", precision=10, scale=2)*/private $usdAmount;/*** @var integer** @ORM\Column(name="aging", type="integer", length=10)*/private $aging;/*** Get id** @return integer*/public function getId(){return $this->id;}/*** Set referenceCode** @param string $referenceCode** @return Balance*/public function setReferenceCode($referenceCode){$this->referenceCode = $referenceCode;return $this;}/*** Get referenceCode** @return string*/public function getReferenceCode(){return $this->referenceCode;}/*** Set documentDate** @param \DateTime $documentDate** @return Balance*/public function setDocumentDate($documentDate){$this->documentDate = $documentDate;return $this;}/*** Get documentDate** @return \DateTime*/public function getDocumentDate(){return $this->documentDate;}/*** Set documentNumber** @param string $documentNumber** @return Balance*/public function setDocumentNumber($documentNumber){$this->documentNumber = $documentNumber;return $this;}/*** Get documentNumber** @return string*/public function getDocumentNumber(){return $this->documentNumber;}/*** Set documentType** @param string $documentType** @return Balance*/public function setDocumentType($documentType){$this->documentType = $documentType;return $this;}/*** Get documentType** @return string*/public function getDocumentType(){return $this->documentType;}/*** Set debtExpireDate** @param \DateTime $debtExpireDate** @return Balance*/public function setDebtExpireDate($debtExpireDate){$this->debtExpireDate = $debtExpireDate;return $this;}/*** Get debtExpireDate** @return \DateTime*/public function getDebtExpireDate(){return $this->debtExpireDate;}/*** Set arsAmountFloat** @param string $arsAmount** @return Balance*/public function setArsAmount($arsAmount){$this->arsAmount= $arsAmount;return $this;}/*** Get arsAmountFloat** @return string*/public function getArsAmount(){return $this->arsAmount;}/*** Set usdAmount** @param string $usdAmount** @return Balance*/public function setUsdAmount($usdAmount){$this->usdAmount = $usdAmount;return $this;}/*** Get usdAmount** @return string*/public function getUsdAmount(){return $this->usdAmount;}/*** Set aging** @param integer $aging** @return Balance*/public function setAging($aging){$this->aging = $aging;return $this;}/*** Get aging** @return integer*/public function getAging(){return $this->aging;}/*** Set account** @param Account $account** @return Balance*/public function setAccount(Account $account = null){$this->account = $account;return $this;}/*** Get account** @return Account*/public function getAccount(){return $this->account;}}This is my migration script:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102<?php/*** Created by PhpStorm.* User: fherrero* Date: 11/10/16* Time: 2:09 PM*/namespace Biotay\Bundle\AccountBundle\Migrations\Schema\v1_5;use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;use Oro\Bundle\MigrationBundle\Migration\Migration;use Oro\Bundle\MigrationBundle\Migration\QueryBag;class CreateBalanceEntity implements Migration, ExtendExtensionAwareInterface{/*** @var ExtendExtension*/private $extendExtension;/*** Sets the ExtendExtension** @param ExtendExtension $extendExtension*/public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}/*** Modifies the given schema to apply necessary changes of a database* The given query bag can be used to apply additional SQL queries before and after schema changes** @param Schema $schema* @param QueryBag $queries* @return void*/public function up(Schema $schema, QueryBag $queries){$this->createBalanceTable($schema);$this->createAccountRelation($schema);}/*** Create Balance table** @param Schema $schema*/protected function createBalanceTable(Schema $schema){$table = $schema->createTable($this->extendExtension->getTableNameByEntityClass('Biotay\Bundle\AccountBundle\Entity\Balance'));$table->addColumn('id', 'integer', ['autoincrement' => true]);$table->addColumn('reference_code', 'string', ['length' => 255]);$table->addColumn('document_date', 'date', []);$table->addColumn('document_number', 'string', ['length' => 255]);$table->addColumn('document_type', 'string', ['length' => 255]);$table->addColumn('debt_expire_date', 'date', []);$table->addColumn('ars_amount', 'decimal', ['scale' => 2]);$table->addColumn('usd_amount', 'decimal', ['scale' => 2]);$table->addColumn('aging', 'integer', []);$table->setPrimaryKey(['id']);}/*** @param Schema $schema*/protected function createAccountRelation(Schema $schema){$tableAccount = $this->extendExtension->getTableNameByEntityClass('OroB2B\Bundle\AccountBundle\Entity\Account');$tableBalance = $this->extendExtension->getTableNameByEntityClass('Biotay\Bundle\AccountBundle\Entity\Balance');$this->extendExtension->addManyToOneRelation($schema,$schema->getTable($tableBalance),'account',$schema->getTable($tableAccount),'id',['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);$this->extendExtension->addManyToOneInverseRelation($schema,$tableBalance,'account',$tableAccount,'balances',['name'],['name'],['name'],['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);}}The addManyToOne relation method works fine. But when the migration command executes the addManyToOneInverseRelation, I get the following error:
[Doctrine\ORM\Mapping\MappingException]
The association mapping ‘balances’ misses the ‘targetEntity’ attribute.What am I doing wrong? Is this a bug? I just want this inverse relation to use the “balances” association field in a query builder.
Thanks!
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.