[英]Symfony 5 - Twig - Access entity.entityB.entityC.property cost many requests
on one of my pages, I display a list of clients, with information such as their country, or the name of their company.在我的一个页面上,我显示了一份客户列表,其中包含他们的国家或公司名称等信息。
So I proceeded as follows:所以我进行如下:
Repository:存储库:
public function findAllAvailableCustomers()
{
return $this->createQueryBuilder('s')
->join('s.user', 'u')
->join('u.entreprise', 'e')
->leftJoin('s.subscription', 'ss')
->leftJoin('ss.plan', 'sp')
->addSelect('ss')
->where('e.willBeDeleted = false')
->orderBy('s.createdAt', 'DESC')
->getQuery()
->getResult();
}
Twig: Twig:
//...
<td>{{ customer.user.email }}</td>
<td>{{ customer.denomination }}</td>
<td>{{ customer.user.entreprise.nom }}</td> // generates 11 requests
//...
I don't understand how I could alleviate the number of queries caused by displaying the client's company name.我不明白如何减少因显示客户公司名称而引起的查询次数。
I tried to add fetch="EXTRA_LAZY"
at StripeCustomer.user
and User.entreprise
entity properties but nothing.我试图在
StripeCustomer.user
和User.entreprise
实体属性中添加fetch="EXTRA_LAZY"
但没有。
I tried also to add this at the request:我还尝试应要求添加此内容:
->addSelect('u, e, ss')
but it generates 600 requests more ->addSelect('u, e, ss')
但它会产生 600 个请求
SO I don't know... :/所以我不知道...:/
You should also select the enterprise entity in your first query:您还应该在第一个查询中 select 企业实体:
public function findAllAvailableCustomers()
{
return $this->createQueryBuilder('s')
->join('s.user', 'u')
->join('u.entreprise', 'e')
->leftJoin('s.subscription', 'ss')
->leftJoin('ss.plan', 'sp')
->addSelect('e') // <--- HERE
->addSelect('ss')
->where('e.willBeDeleted = false')
->orderBy('s.createdAt', 'DESC')
->getQuery()
->getResult();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.