Skip to content

Manage innerJoin not nullable associations #22

Closed
@soullivaneuh

Description

@soullivaneuh

With this PHP code:

$qb = $this->invoiceRepository->createQueryBuilder('i')
    ->select('i, c, ba')
    ->innerJoin('i.customer', 'c', Expr\Join::WITH, 'c.automaticPaymentMethod = :automatic_payment_method')
    ->innerJoin('c.bankAccount', 'ba', Expr\Join::WITH, 'ba.activated = :activated AND ba.mandateSigned = :mandateSigned AND ba.mandateSignedDate IS NOT NULL')

foreach ($invoices as $invoice) {
    $customer = $invoice->getCustomer();
    $bankAccount = $customer->getBankAccount();

    $bankAccount->setFirstDebit(true);
    $this->persist($bankAccount);
}
;

I'll have this error:

Parameter #1 $object of method Doctrine\Common\Persistence\ObjectManagerDecorator::persist() expects object, AppBundle\Entity\BankAccount|null given.

But this is not true as innerJoin will drop customers without a bank account. Am I right?

If I'm right, checking if $bankAccount in this case is overkill and will never match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions