I am using Doctrine 3.1 with some EXTRA_LAZY associations.
OneToMany and OneToOne association work well but When I try an EXTRA_LAZY ManyToMany association, the ->matching($criteria) methods has a strange behavior. The Criteria::expr()->contains create an invalid sql.
The following AND te.name CONTAINS ? is added to the Sql query.
Other associations (OneToOne and OneToMany) create a valid SQL with a like % %.
Do you know how to solve this problem?
After declaring a ManyToMany association in my class A :
#[ORM\JoinTable(name: 'association_A_B')]
#[ORM\JoinColumn(name: 'A_id', referencedColumnName: 'A_id')]
#[ORM\InverseJoinColumn(name: 'B_id', referencedColumnName: 'B_id')]
#[ORM\ManyToMany(targetEntity: B::class, fetch: "EXTRA_LAZY")]
private Collection $b;
This code :
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->contains("name", "searchString"));
return $this->b->matching($criteria);
failed with this error :
An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONTAINS
To better understand the problem, I modified the Doctrine code to hard replace the CONTAINS by a LIKE : it seems to work fine. I don't understand why Doctrine doesn't handle CONTAINS correctly in this case.