简体   繁体   中英

Symfony2 entity attributes are ignored

I'm stuck on a weird behaviour with Symfony2.

I have an entity that represent Documents in my App. This entity is linked to two other entities with ManyToOne relationship.
Here is the class :

Entity\\Document.php

namespace Acem\APPBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="documents")
 */
class Document
{
    /** 
     * @ORM\Id()
     * @ORM\ManyToOne(targetEntity="Resource", inversedBy="documents") 
     * @ORM\JoinColumn(name="resource_id", referencedColumnName="id", nullable=false) 
     */
    protected $resource;

    /** 
     * @ORM\Id()
     * @ORM\ManyToOne(targetEntity="User", inversedBy="documents") 
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) 
     */
    protected $owner;

    /**
     * ORM\Column(type="boolean")
     */
    protected $enabled;

    /**
     * ORM\Column(type="string")
     */
    protected $title;

    /**
     * ORM\Column(type="int")
     */
    protected $value;

}

My problem is that doctrine only generates a table with two columns resource_id and user_id but the other fields are totally ignored.
Same thing happens when I use doctrine:generate:entities , the getters / setters are generated only for the two attributes that have a ManyToOne relationship but the others seem not to exist for Doctrine.

What may cause that strange behaviour and how to fix it ?

Thanks

Add an @ symbol for each field reference. It would look like @ORM\\Column... then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM