簡體   English   中英

通過關系一對多原則獲取屬性

[英]get attribute with Relation OneToMany doctrine

我在symfony平台上工作,有兩個與OneToMany相關的實體“ Product and Producter”,為了顯示“ Product”列表,我希望顯示每個“ Producter”的徽標

產品

class Product
 {

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

protected $owner;

生產者

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;

我在嘗試使生產者的象形文字出現問題時遇到問題(不存在可變路徑)

我認為您忘記將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();
        }

就像以前寫的那樣-將產品名稱重命名為產品。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM