Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 command "doctrine:schema:update" not detect trait file changes used in entities

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.

like image 691
Ravz Avatar asked Jan 14 '14 18:01

Ravz


4 Answers

You can force this by doing:

php app/console cache:clear
php app/console doctrine:schema:update --force
like image 85
Matthew Davis Avatar answered Nov 02 '22 08:11

Matthew Davis


Try to enable Doctrine auto mapping and remove this folder : YourBundle\Resources\config\doctrine

like image 27
FAROUK BLALOU Avatar answered Nov 02 '22 09:11

FAROUK BLALOU


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
like image 8
Dima Kurilo Avatar answered Nov 02 '22 09:11

Dima Kurilo


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: ~
like image 2
Saman Mohamadi Avatar answered Nov 02 '22 09:11

Saman Mohamadi