This topic contains 8 replies, has 2 voices, and was last updated by adriwan_kenoby 8 years ago.
- Topic
Hi,
I use a migration file to extend Account of the OroCRMAccountBundle.When i run it the first time i have this errors:
[LogicException]
A new model can be created for custom entity only. Class: Sinabs\MonitoringBundle\Entity\WebSite./…
[RuntimeException]
Failed migrations: Oro\Bundle\EntityExtendBundle\Migration\UpdateExtendConfigMigration.But the database have changed accordingly.
Then when i run doctrine:schema:update it erase the changes done by the migration script.
Here my code
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139<?phpnamespace Sinabs\MonitoringBundle\Entity;use Doctrine\ORM\Mapping as ORM;/*** WebSite** @ORM\Table()* @ORM\Entity(repositoryClass="Sinabs\MonitoringBundle\Entity\WebSiteRepository")*/class WebSite {/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @var string** @ORM\Column(name="name", type="string", length=255)*/private $name;/*** @var string** @ORM\Column(name="url", type="string", length=255)*/private $url;/****/private $account;/*** @ORM\OneToMany(targetEntity="Sinabs\MonitoringBundle\Entity\Sonde", mappedBy="webSite", cascade={"persist", "remove"})*/private $sondes;/*** Constructor*/public function __construct() {$this->sondes = new \Doctrine\Common\Collections\ArrayCollection();}/*** Get id** @return integer*/public function getId() {return $this->id;}/*** Set name** @param string $name** @return WebSite*/public function setName($name) {$this->name = $name;return $this;}/*** Get name** @return string*/public function getName() {return $this->name;}/*** Set url** @param string $url** @return WebSite*/public function setUrl($url) {$this->url = $url;return $this;}/*** Get url** @return string*/public function getUrl() {return $this->url;}/*** Add sonde** @param \Sinabs\MonitoringBundle\Entity\Sonde $sonde** @return WebSite*/public function addSonde(\Sinabs\MonitoringBundle\Entity\Sonde $sonde) {$this->sondes[] = $sonde;return $this;}/*** Remove sonde** @param \Sinabs\MonitoringBundle\Entity\Sonde $sonde*/public function removeSonde(\Sinabs\MonitoringBundle\Entity\Sonde $sonde) {$this->sondes->removeElement($sonde);}/*** Get sondes** @return \Doctrine\Common\Collections\Collection*/public function getSondes() {return $this->sondes;}}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990<?phpnamespace Sinabs\MonitoringBundle\Entity;use Doctrine\ORM\Mapping as ORM;/*** Sonde** @ORM\Table()* @ORM\Entity(repositoryClass="Sinabs\MonitoringBundle\Entity\SondeRepository")*/class Sonde {/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @var string** @ORM\Column(name="url", type="string", length=255)*/private $url;/*** @ORM\ManyToOne(targetEntity="Sinabs\MonitoringBundle\Entity\WebSite", inversedBy="sondes")* @ORM\JoinColumn(nullable=false)*/private $webSite;/*** Get id** @return integer*/public function getId() {return $this->id;}/*** Set url** @param string $url** @return Sonde*/public function setUrl($url) {$this->url = $url;return $this;}/*** Get url** @return string*/public function getUrl() {return $this->url;}/*** Set webSite** @param \Sinabs\MonitoringBundle\Entity\WebSite $webSite** @return Sonde*/public function setWebSite(\Sinabs\MonitoringBundle\Entity\WebSite $webSite) {$this->webSite = $webSite;return $this;}/*** Get webSite** @return \Sinabs\MonitoringBundle\Entity\WebSite*/public function getWebSite() {return $this->webSite;}}:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849<?phpnamespace Sinabs\MonitoringBundle\Migrations\Schema\v1_0;use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;use Oro\Bundle\MigrationBundle\Migration\Migration;use Oro\Bundle\MigrationBundle\Migration\QueryBag;class OroCRMAccountMigration implements Migration, ExtendExtensionAwareInterface {protected $webSites;public function setExtendExtension(ExtendExtension $extendExtension) {$this->webSites = $extendExtension;}public function up(Schema $schema, QueryBag $queries) {$webSites = $this->webSites;/** extend table orocrm_account * */$table = $schema->getTable('orocrm_account');/*** define and add our custom fields*/$webSites->addOneToManyRelation($schema,$table, // owning side table'webSites', // owning side field name'WebSite', // target side table['name'], // column names are used to show a title of related entity['name'], // column names are used to show detailed info about related entity['name'], // Column names are used to show related entity in a grid['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);$webSites->addOneToManyInverseRelation($schema,$table, // owning side table'webSites', // owning side field name'WebSite', // target side table'account', // target side field name'name', // column name is used to show related entity['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);}}It seems like i have forgot some steps before define migration script correctly.
Sorry for my english… I am french
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.