产品和图像是通过oneToMany关联关联的两个实体(一个产品具有多个图像)。我尝试用嫩枝每个产品枚举与第一图像(文件名田间)是这样的:Symfony,OneTwoMany,树枝中的第一个子元素
class ProductRepository extends EntityRepository
{
public function getProductsWithImages() {
$query = $this->createQueryBuilder('e')
->leftJoin('e.images', 'i', 'with', 'i.order = :order')
->setParameter('order' , 0)
->select('e')
->addSelect('i');
return $query->getQuery()->getResult();
}
}
但我得到这个错误:
Method "filename" for object "\entity\product" does not exist.
我明白为什么(产品实体没有图像字段)。没有添加父对象的引用(像mainImage字段),只得到一个子元素的最佳实践是什么?
告诉我们您的树枝代码 - 为问题可能有 –