ibi0tux
ibi0tux

Reputation: 2629

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

Upvotes: 1

Views: 114

Answers (1)

Ilya Yarkovets
Ilya Yarkovets

Reputation: 840

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

Upvotes: 2

Related Questions