api-platform / api-platform/core
loadClassMetadata properties are ignored in GET operations
- 主要语言
- 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 还没有评估数据。