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. 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. 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
->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
Expected argument of type "Doctrine\\ORM\\QueryBuilder", "string" given
How can I solve this problem?
Thanks for your help. ;)
As i think, you can use andWhere statement like :
$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;
Inspired on this .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.