【发布时间】:2023-03-24 09:39:01
【问题描述】:
我在 Symfony2 中有以下实体,一个产品实体和一个 cmets 实体。
产品实体:
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
cmets 实体:
/**
* @ORM\Entity
* @ORM\Table(name="productComment")
*/
class ProductComment
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Acme\ProductsBundle\Entity\Product", inversedBy="comments")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
*/
protected $product;
}
我的问题是我不知道如何从产品对象中获取 cmets。
【问题讨论】:
标签: symfony doctrine many-to-one