I have two entity classes, Product
and OrderEntry
, defined like this (some annotations left out for compactness):
class Product {
/**
* @Id
*/
protected $id;
/**
* @Column()
* @Id
*/
protected $prodNumber;
/**
* @Column()
* @Id
*/
protected $group;
// more cols here
}
class OrderEntry {
// more cols here
/**
* @ManyToOne(targetEntity="Product")
* @JoinColumns({
* @JoinColumn(name="prodNumber", referencedColumnName="prodNumber"),
* @JoinColumn(name="group", referencedColumnName="group")
* })
*/
protected $Product;
}
Now I want to find an OrderEntry by its associated Product with the query builder. The most logical thing for me would be this:
class OrderEntryRepository extends EntityRepository {
public function findByProduct($product) {
$qb = $this->getQueryBuilder('o');
$qb->where($qb->expr()->eq('o.Product', '?1')
->setParameter(1, $product)
->setMaxResults(1);
return $qb->getQuery()->execute();
}
}
However, this throws an exception that says
A single-valued association path expression to an entity with a composite primary key is not supported. Explicitly name the components of the composite primary key in the query.
How do I name the components explicitly? I know I could do it with a JOIN, but I have no use for the Product in this case and it would just make the query more expensive.