4
多対多関係で異なる列名を持つプロパティに対して簡単な条件を使用しようとすると、Doctrineはpropertynameをフィールドとして使用します列名条件と多対多関係のクエリーで間違ったフィールド名
人異なるColumnNameに
...
name:
type: string
nullable: false
length: 50
options:
fixed: false
column: '`key`'
...
人::は、hasAttribute()とのORMの定義
...
manyToMany:
attributes:
targetEntity: Attributes
cascade: ['persist']
joinTable:
name: person_attribute
joinColumns:
person_id:
referencedColumnName: id
inverseJoinColumns:
attribute_id:
referencedColumnName: id
...
属性ORMの定義 - 方法
$criteria = Criteria::create()
->where(Criteria::expr()->eq('name', $attributeName))
->setFirstResult(0)
->setMaxResults(1);
if ($this->getAttributes()->matching($criteria)->first()) {
return true;
}
生成された声明
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` = ?"
条件を "キー"に変更すると、DoctrineがDBからリレーションをロードする必要があるときに機能しますが、自分のユニットテストでPHP致命的になります。なぜなら、キー "または" getKey "。 – Sebus
アクセスは対応するクラスのプロパティに設定されていますか?デフォルトでは、アクセスはFIELDですか? –
Doctrine ORMのバージョンは何ですか? –