[英]Symfony2: How do I use in a form (query builder) left join and isnull?
I have a problem with a filter function for which I am using two tables.我使用两个表的过滤器函数有问题。 The first ‚eventcheckin-table' is used for checking in the guests via booking-ID for a certain event.
第一个“事件签到表”用于通过预订 ID 为特定事件签入客人。 Therfore it should also verify if the ID is already checked in. The ID´s which aren´t yet checked in shall be available as an option in the ‚Entity' field.
因此,它还应验证该 ID 是否已签入。尚未签入的 ID 应作为“实体”字段中的选项可用。 This problem I tried to solve in the following way:
这个问题我尝试通过以下方式解决:
SELECT booking.booking_id FROM booking LEFT JOIN event_checkin ON `event_checkin.booking_booking_id = booking.booking_id WHERE` event_checkin.booking_booking_id IS NULL
It works fine.它工作正常。
My solution for the Symfony2 Form Builder is我对 Symfony2 Form Builder 的解决方案是
->add('bookingBooking', EntityType::class, array (
'class' => 'AppBundle:Booking',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('b')
->leftjoin('AppBundle:EventCheckin', 'e', 'with', 'e.bookingBooking = b.Id')
->expr()->isNull('e.bookingbooking');
},
'label' => 'Booking-ID: * ',
))
Symfony displays this message Symfony 显示此消息
Expected argument of type "Doctrine\\ORM\\QueryBuilder", "string" given
给定类型为“Doctrine\\ORM\\QueryBuilder”、“string”的预期参数
How can I solve this problem?我怎么解决这个问题?
Thanks for your help.谢谢你的帮助。 ;)
;)
As i think, you can use andWhere statement like :我认为,您可以使用andWhere语句,例如:
$er->createQueryBuilder('b')
->leftjoin('AppBundle:EventCheckin', 'e', 'with', 'e.bookingBooking = b.Id')
->andWhere('e.bookingbooking is null');
Or或者
$qb = $er->createQueryBuilder('b');
$qb->leftjoin('AppBundle:EventCheckin', 'e', 'with', 'e.bookingBooking = b.Id')
->add('where', $qb->expr()->isNull('e.bookingBooking'));
return $qb;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.