api-platform / api-platform/core

loadClassMetadata properties are ignored in GET operations

未關閉
#7,999 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
doctrine State
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 5 小時
30 天內合併 PR
48

描述

**API Platform version(s) affected**: 2.1

**Description**
Properties or associations added through Doctrine's `loadClassMetadata` event do not work in GET operations. They work properly in POST/PUT and the value gets stored in the database, but when doing a GET operation the same properties come up as empty.

My suspicion is that maybe data providers get initialized before doctrine listeners are registered, but my knowledge on the internals of API platform is not good enough to try and fix, so I'm writing it here.

**How to reproduce**
1. Create a doctrine listener and bind `loadClassMetadata` to it
2. Create an entity and add a property or an association to it through the listener.
3. Run a **POST** operation to create an object. The created property will work fine and show the correct value. The database will also have the correct value stored.
4. Run a **GET** operation on either the collection or the item. The created property will be null even if the value in the database is correct. Doctrine effectively does not know about the property.

**Possible Solution**
In my project I worked around the issue by creating a request listener with high priority containing only the following line:

`$this->doctrine->getManager()->getMetadataFactory()->getAllMetadata($curClass);`

The above code fixes the issue, but it is hacky and seems to slightly degrade performance. I would much prefer if we can find the root of the bug and properly fix the issue.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。