I have an entity offer which has a oneToOne relation with a product and I have a user who would like to get all the offers he got on his products.
I would like to access to the user who has made the product from an offer in my SQL request.
So it's something like that:
$user = $this->getUser();
$listofofferusergot = $em->getRepository('blabla:Offer')->findBy(array('product.autor.id' => $user->getId()));
(ps : Offer has a OneToOne relation with product) (ps2: the thing I wrote doesn't work )
So the question is general Can I simply access to a subfield (like id in my case) or must I do a $em->createQuery() stuff
offer class:
<?php
namespace Nemi\TwigBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Offer
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Nemi\TwigBundle\Entity\OfferRepository")
*/
class Offer
{
/**
* @ORM\ManyToOne(targetEntity="Nemi\TwigBundle\Entity\Product")
* @ORM\JoinColumn(nullable=false)
*/
private $product;
...
}
for the product class:
<?php
namespace Nemi\TwigBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Nemi\TwigBundle\Entity\ProductRepository")
*/
class Product
{
/**
* @ORM\ManyToOne(targetEntity="Nemi\UserBundle\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $autor;
....
}