I have a Trait file with shared code between entities.
trait file example:
<?php
namespace Acme\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* BaseHtml Trait
*
*/
trait BaseHtml
{
/**
* @var integer
*
* @ORM\Column(name="status", type="string", length=20)
*/
private $status;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
private $date;
public function setStatus($status)
{
$this->status = $status;
return $this;
}
public function getStatus()
{
return $this->status;
}
public function setDate($date)
{
$this->date = $date;
return $this;
}
public function getDate()
{
return $this->date;
}
}
Entity file example:
<?php
namespace Acme\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Page
*
* @ORM\Table()
* @ORM\Entity
*
*
*/
class Page
{
use BaseHtml;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Gallery")
*/
private $gallery;
public function getId()
{
return $this->id;
}
public function setGallery(\Application\Sonata\MediaBundle\Entity\Gallery $gallery)
{
$this->gallery = $gallery;
return $this;
}
public function getGallery()
{
return $this->gallery;
}
}
But when I modify the annotations of trait file or add new columns and execute "php app/console doctrine:schema:update":
Nothing to update - your database is already in sync with the current entity metadata.
I need change manually date modification of all entities files who use traits file for get doctrine:schema:update run properly.
I tried with commands
php app/console doctrine:cache:clear-metadata
php app/console cache:clear
before execute doctrine:schema:update, but without result.
Any idea for don't manually update entities files and doctrine:schema:update detect updates of entities when change traits file, i lost part of advantages of sharing code with traits.
You can force this by doing:
php app/console cache:clear
php app/console doctrine:schema:update --force
Try to enable Doctrine auto mapping and remove this folder : YourBundle\Resources\config\doctrine
May be I'm too late, but if you use memcache you need to clear memcache too. So you need to do something like:
echo 'flush_all' | nc yourhost 11211
php app/console cache:clear
php app/console doctrine:schema:update
It is possible that you forget to enable Doctrine auto mapping;
orm:
#auto_mapping: true
If auto mapping is disabled (or commented like above) , you should register Entiteis of each bundle manually.
orm:
entity_managers:
default:
mappings:
AcmeHelloBundle: ~
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With