-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vich\Uploadable not working correctly with OneToOne relation #1409
Comments
My suggestion is avoiding to use entities with autoincrement ids or in general entities which depend on their database status, which defeats the main purpose of using a data mapper (independence between entities and the persistence layer) |
@garak the problem is not the id, it is the path of file returned. The id is just another indicator that something is not working properly. In the third dump it returns the file ...440.jpg (which is the original file before replacing the relation), after calling refresh() it returns the file ...584.jpg which is the correct one. |
Using 2.2.0, the old problem of not working on Doctrine proxy objects is there again. I think this might be related / the same thing? I have an entity If I request any property from the There are old issues about the same thing that had fixes: #28 I encounter this with an old Symfony 3.4 project that has been upgraded to Symfony 6. |
Bug Report
Summary
When having an entity with a relation
OneToOne
with other entity with aVichUploadable
file, on changing the relation and flushing the related entity is not properly updated in php, although in database is properly updated. A refresh of the entity is required to get the updated value.Current behavior
I have an entity Item with a relation OneToOne with ItemImage that is a Vich\Uploadable entity. When updating this entity, after flushing it to the database, the previous entity is loaded in the relation without an Id instead the new entity that has been stored in the database.
How to reproduce
This is the source code:
Item.php
ItemImage.php
vich_uploader.yaml
Execute the following code:
Expected behavior
The third dump, shold be the same as the fourth dump. Shoud be a
ItemImage
entity with id=11 and filename ...584.jpg, instead the id is null and the filename is ...440.jpg (the original filename before being replaced).If before setting the new image, you fully load the entity (doing a
$item->getImage()->getFile()
for example) then the first dump is not a Proxy, and it works fine. So there must be an issue with the use of Proxies.Removing
#[Vich\Uploadable]
fromItemImage
, works fine (although the image will not be handled) so it seems that is not an issue of doctrine.The text was updated successfully, but these errors were encountered: