Hi,
i've an issue with isNull method from Expression class
this is an example i use in my entity :
public function getValidDiscountOffers(): Collection
{
$expr = Criteria::expr();
$criteria = Criteria::create()
->where($expr->eq('active', true))
->andWhere($expr->isNull('validityStart'))
;
return $this->discountOffers->matching($criteria);
}
And this is the result SQL from log :
WHERE t.user_id = ? AND te.active = ? [145,false] []
No trace about IS NULL
And If i try to replace my validityStart variable by another whose doesn't exist, no error returned
But if i replace isNull method by eq method an error is trigger ... It seems to skip my expression when isNull...
Thanks for reading
BenWa
@BenWaNH would you be able to write a test case that reproduces this issue? See https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket for examples.
Yes, I will write it next week. I have to stay my time for this week and I will use the filter in the meantime.
Thanks
Hey @BenWaNH , I've created a test case for that, but I was not able to reproduce the error (version 2.7). Looks good to me. I took the opportunity to create a functional test that demonstrates that. See #7874.
If so, maybe we could close this issue.
@thicolares This issue is valid for ManyToManyPersister and SqlValueVisitor https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php#L32-L36
I can confirm that this issue exists for ManyToMany relationships but not for ManyToOne relationships.
Our entity model looks like this:
Organisation:
- OneToMany TemplateType
Template:
- ManyToMany TemplateType
TemplateType:
- ManyToOne Organisation
- ManyToMany Template
- DateTime archivedAt
Doing a Criteria::expr()->isNull('archivedAt') on Organisation::templateTypes correctly filters out archived TemplateTypes.
Doing a Criteria::expr()->isNull('archivedAt') on Template::templateTypes when templateTypes is uninitialized does not filter correctly because archived_at IS NULL is left off the SQL query.
However, if templateTypes is initialized, then Criteria uses array_filter and it works as expected.
So the issue is only present when calling PersistentCollection::matching with an initialized collection with an many to many association.
Most helpful comment
@thicolares This issue is valid for ManyToManyPersister and SqlValueVisitor https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php#L32-L36