我有一个实体Article20000Information
,与像几个领域:id
,description
,manufacturer_id
,supplier_id
我还有另一个实体Organisation
。它有一个公司列表(制造商和供应商),每个公司都有一个id
。
我还有一个页面,显示了Article20000Information数据的列表。当前,它仅在表中显示数据,因此:
| id | Description | Manufacturer | Supplier | Price |
|----|-------------|--------------|----------|--------|
| 1 | thing1 | 2 | 5 | 34 |
| 2 | thing2 | 5 | 2 | 23 |
| 3 | thing3 | 3 | 4 | 25 |
我需要的是“制造商”和“供应商”列,以根据显示的ID显示表中的name
值organisation
。
最好的方法是什么?
知道了!
我需要多个别名,但我也想给它们AS
加上别名,以便它们使用不同的列名。反过来,这使树枝可以渲染标签。
<?php
namespace Regenerys\QMSBundle\Entity;
use Doctrine\ORM\EntityRepository;
class Article20000InformationRepository extends EntityRepository
{
public function findStuff()
{
return $this->getEntityManager()
->createQuery(
'SELECT
A.id,
A.articleNumber,
A.description,
B.name as manufacturer,
C.name as supplier
FROM
RegenerysQMSBundle:Article20000Information A
LEFT OUTER JOIN RegenerysQMSBundle:Organisation B WITH B.id = A.manufacturer
LEFT OUTER JOIN RegenerysQMSBundle:Organisation C WITH C.id = A.supplier '
)
->getResult();
}
}
感谢@Alexandru对DQL的帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句