i have the following entities in Symfony2, a products entity and a comments entity.
The products entity:
/**
* @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;
The comments entity:
/**
* @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;
}
My problem it's that i don't know how to get the comments from a product objects.
You have to add a comments property into the Product entity:
/**
* @ORM\OneToMany(targetEntity="Acme\ProductsBundle\Entity\ProductComment", mappedBy="product")
*/
private $comments;
And then use
$product->getComments();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With