0
votes

Some how whatever changes i make in my entites,doctrine doesn't seem to update it.I know there are already some similar questions.I have gone through them and tried :

php app/console cache:clear php app/console doctrine:cache:clear-metadata

php app/console doctrine:schema:update --force

I have never imported the database,so there are no orm.yaml files in my src folder.

I am using mysql database with symfony and doctrine as orm.

here is my config

doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

doctrine:schema:validate gives me this:

[Mapping]  FAIL - The entity-class 'Madhuri\TermsBundle\Entity\RelatedTerm' mapping is invalid:
* The association Madhuri\TermsBundle\Entity\RelatedTerm#term1 refers to the inverse side field Madhuri\TermsBundle\Entity\Term#relatedTerm which does not exist.

My entities are Term.php

namespace Madhuri\TermsBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Term
 *
 * @ORM\Table(name="terms")
 * @ORM\Entity
 */
class Term
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="termName", type="string", length=255)
     */
    private $termName;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="string", length=2000)
     */
    private $description;

    /**
     * @var string
     *
     * @ORM\Column(name="mnemonic", type="string", length=2000)
     */
    private $mnemonic;

    /**
     * @var ArrayCollection
     *
     * @ORM\OneToMany(targetEntity="RelatedTerm",
     *                mappedBy="term1")
     */
    private $relatedTerms;

    // /**
    //  * @var ArrayCollection
    //  *
    //  * @ORM\OneToMany(targetEntity="TermExamples",
    //  *                mappedBy="term")
    //  */
    // private $termExamples;


    public function __construct()
    {
      $this->relatedTerms  = new ArrayCollection();
      $this->$termExamples = new ArrayCollection();
    }
    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get Related Terms
     */
    public function getRelatedTerms()
    {
      return $this->relatedTerms ;
    }

    /**
     * Add related term
     */
    public function addRelatedTerm($relatedTerm)
    {
        $this->relatedTerms[] = $relatedTerm;
    }

    /**
     * Clear related Terms
     */
    public function clearRelatedTerms()
    {
        $this->relatedTerms->clear();
    }

    /**
     * Remove a related Term
     */
    public function removeRelatedTerm($relatedTerm)
    {
        $this->relatedTerms->removeElement($relatedTerm);
    }

    /**
     * Get Term Examples
     */
    // public function getTermExamples()
    // {
    //   return $this->termExamples ;
    // }
    //
    // /**
    //  * Add term example
    //  */
    // public function addTermExample($termExample)
    // {
    //     $this->termExamples[] = $termExample;
    // }
    //
    // /**
    //  * Clear term examples
    //  */
    // public function clearTermExamples()
    // {
    //     $this->termExamples->clear() ;
    // }
    //
    // /**
    //  * Remove a Term Example
    //  */
    // public function removeTermExample($termExample)
    // {
    //     $this->termExamples->removeElement($termExample);
    // }

    /**
     * Set termName
     *
     * @param string $termName
     * @return Term
     */
    public function setTermName($termName)
    {
        $this->termName = $termName;

        return $this;
    }

    /**
     * Get termName
     *
     * @return string
     */
    public function getTermName()
    {
        return $this->termName;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Term
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set mnemonic
     *
     * @param string $mnemonic
     * @return Term
     */
    public function setMnemonic($mnemonic)
    {
        $this->mnemonic = $mnemonic;

        return $this;
    }

    /**
     * Get mnemonic
     *
     * @return string
     */
    public function getMnemonic()
    {
        return $this->mnemonic;
    }



}

RelatedTerm.php

<?php

namespace Madhuri\TermsBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * RelatedTerms
 *
 * @ORM\Table(name="related_terms")
 * @ORM\Entity
 */
class RelatedTerm
{
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;

  /**
   * @var Term
   *
   * @ORM\ManyToOne(targetEntity="Term",
   *                inversedBy="relatedTerm")
   */
   private $term1;

   /**
    * @var Term
    *
    * @ORM\ManyToOne(targetEntity ="Term")
    */
    private $term2;

    /**
     * @var string
     *
     * @ORM\Column(name="notes", type="string", length=2000, nullable=true)
     */
    private $notes;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get term1
     *
     * @return Term
     */
    public function getTerm1()
    {
       if($this->term1)
        {
          return $this->term1;
        }
       else {
         return null;
       }
    }

    /**
     * Set term1
     *
     * @param Term $term1
     *
     * @return Term
     */
    public function setTerm1(Term $term1)
    {
        $this->term1 = $term1;

        return $this;
    }

    /**
     * Get term2
     *
     * @return Term
     */
    public function getTerm2()
    {
        return $this->term2;
    }

    /**
     * Set term2
     *
     * @param Term $term2
     *
     * @return Term
     */
    public function setTerm2( Term $term2)
    {
        $this->term2 = $term2;

        return $this;
    }

    /**
     * Get notes
     *
     * @return string
     */
    public function getNotes()
    {
        return $this->notes;
    }

    /**
     * Set notes
     *
     * @param string $notes
     *
     * @return Term
     */
    public function setNotes($notes)
    {
        $this->notes = $notes;

        return $this;
    }

}

 ?>
1
Do you get any errors?Jason Hendry
No,I just get schema is upto dateuser3425344
Actually I had an entity which threw an error.It had some error in annotations.I removed that whole entity and tried to update ,From then whatever changes i do,It doesnt get updated.user3425344
Does --dump-sql show any SQL?Jason Hendry
No,it doesnt show any error.user3425344

1 Answers

0
votes

If you are using doctrine without framework (like i do), delete the calling to doctrine as ORM (maybe not needed)

use Doctrine\ORM\Mapping as ORM;

then replace all the @ORM\ for just @.

This was stopping doctrine from recognizing the class and its changes. Hope it helps