When I try to use a simple Criteria on a property with a different columnname in Many-To-Many-Relation, Doctrine uses the propertyname as the field and not the columnname.
Person ORM Definition
...
manyToMany:
attributes:
targetEntity: Attributes
cascade: ['persist']
joinTable:
name: person_attribute
joinColumns:
person_id:
referencedColumnName: id
inverseJoinColumns:
attribute_id:
referencedColumnName: id
...
Attribute ORM Definition with differing columnname
...
name:
type: string
nullable: false
length: 50
options:
fixed: false
column: '`key`'
...
Person::hasAttribute()-Method
$criteria = Criteria::create()
->where(Criteria::expr()->eq('name', $attributeName))
->setFirstResult(0)
->setMaxResults(1);
if ($this->getAttributes()->matching($criteria)->first()) {
return true;
}
The generated Statement
SELECT
te.id AS id,
te.description AS description,
te.key AS key
FROM
attribute te
JOIN
person_attribute t
ON
t.attribute_id = te.id
WHERE
t.person_id = ?
AND
te.name = ? ## <- This should be "te.`key` = ?"