doctrine / mongodb-odm

The Official PHP MongoDB ORM/ODM
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/
MIT License
1.09k stars 504 forks source link

ReferenceOne to file with orphanRemoval="true" issue #1826

Closed vkhramtsov closed 4 years ago

vkhramtsov commented 6 years ago

Hello

Bug Report

Q A
BC Break yes?
Version 1.2.4

Summary

I'm storing images in database as files like described here https://github.com/doctrine/mongodb-odm/blob/master/docs/en/reference/storing-files-with-mongogridfs.rst. Also I have additional document, which have ReferenceOne relation with this images. Also I have cascade={"persist", "remove"} and orphanRemoval="true" on this relation.

Current behavior

When I'm trying to save this document to database using form, odm delete image even it not changed. It leads to problem, because target image does not exist anymore.

After some time of investigation, I found out that while checking for changes, odm compare image document (coming) with old value, which originally proxy document and have only id. So comparison always indicate coming document as changed and odm remove old one.

How to reproduce

Create document for storing image in database. Create ReferenceOne relation with orphanRemoval="true" from other document with to image. Try to save this document without changing image.

I can try to create unit test or code for reproducing this issue, but it needs some time to extract this code from project.

Expected behavior

Image will stay the same and not deleted.

Thank you in advance

malarzm commented 6 years ago

@vkhramtsov unit test will be appreciated as we'd need to write one anyway :)