I am using dql to query my table.
$dql = "SELECT p FROM WIC\ListingBundle\Entity\Listing p order by p.name";
I have two tables, Listing
and Products
.
In the Listing
Table I have product_id
field which references the Products
Table id
field.
I want to be able to order my query by the Product
Table name
field but I also want to keep getting an error each time I do p.name
. p.name
does NOT exist in the Listing
Table, thats why it is throwing the error, I just don't know how to do it properly.
Listing
entity:
/**
* @ORM\ManyToOne(targetEntity="WIC\ProductBundle\Entity\Product", inversedBy="listings", cascade={"remove","persist"})
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
* @Common\Versioned
* @Assert\NotBlank()
*/
protected $product;
LEFT JOIN
Try this way:
$dql = "SELECT l FROM WIC\ListingBundle\Entity\Listing l LEFT JOIN l.product p order by p.name";