2017-08-04 2 views
1

私はsymfonyプラットフォームで動作し、OneToManyという関係を持つ2つのエンティティ "Product and Producter"を持ち、 "Product"のリストを表示するために、リレーションOneToManyでアトリビュートを取得するdoctrine

製品

class Product 
{ 

/** 
* 
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\Producter",  inversedBy="products") 
* @ORM\JoinColumn(name="pr_id", referencedColumnName="id") 
*/ 

protected $owner; 

Producter

class Producter extends User 
{ 
/** 
    * @ORM\OneToMany(targetEntity="Gestion\CentralBundle\Entity\Product", mappedBy="owner") 
    */ 
    protected $products; 

/** 
    * @ORM\Column(type="string", length=255, nullable=true) 
    */ 
    protected $path; 

プロデューサーの絵描き者をゲットしようとしたときに問題が発生しました(可能なパスが存在しません)

+0

1つの問題は、単にタイプミスのように見えます。 'inversedBy =" products "'となりますが、実際のプロパティは '$ pruducts'と呼ばれます。しかし、他の問題があるかもしれません。 –

答えて

0

arrayCollectionをコンストラクターに追加するのを忘れたと思います。あなたは教義を説明しなければなりません、その製品はオブジェクトのコレクションです!

use Doctrine\Common\Collections\ArrayCollection; 

    class Producter extends User 
    { 
     // ... 

     /** 
     * @ORM\OneToMany(targetEntity="Gestion\CentralBundle\Entity\Product", mappedBy="owner") 
     */ 
     protected $products; 

     public function __construct() { 
      $this->products = new ArrayCollection(); 
     } 

これまでに書かれているように、製品に名前を変更しています。

関連する問題