-
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
The file is not updated if there are not other changes in the entity #8
Comments
I have come across this issue in my current project, but I have not had time to dive into it further. I have just implemented a little hack in my entities right now similar to the following: public function setFile($file)
{
$this->file = $file;
if ($file instanceof UploadedFile) {
$this->setUpdatedAt(new \DateTime());
}
} Hopefully I will have time to look into this soon. |
Thanks :) |
Uhh Ohh dirty! :) |
I believe this is an issue with the framework itself, and not this bundle in particular. I've run up against it as well, independently of this uploader, and I'm looking into it too. |
+1 ;) |
cool workaround, hoping it will be fixed soon |
thanks guys! You have saved my day! |
I have this issue too maybe this could be fixed in this bundle. |
Same issue here. I guess this is because Doctrine doesn't detect any changes when only a file is uploaded as the "file" member variable is not mapped as a database column. I'm just guessing, though. |
This is an issue with doctrine, which wont persist the entity if it doesn't see any changes. I have an issue in the main Symfony project here: symfony/symfony#5150 (comment) |
As I've explained to @aderuwe, this is kinda wrong.
and perform all the persistence operations related to the file itself there. |
Hi @Ocramius, I would like to discuss this with you, will you be available for a quick chat on this topic ? |
@ftassi ping me on IRC tomorrow eventually ( #doctrine ) |
Same problem, still waiting... Thanks. |
@dustin10, maybe you have a normal solution? much time has passed. |
Doctrine uses identical operator (===) to compare changes between old and new values. The operator used on the same object with different data always return true. The best way is to clone the object. |
@stof, maybe you can help resolve this problem? |
Guys, I researched this issue and think it's unsolvable problem for current architecture :( This hack should be added to the documentation |
maybe |
@Koc I tried. I couldn't get entity in |
The only way to go is, to use the $form = $this->createForm(new AcmeType(), $entity);
$form->bind($request);
if ($form->isValid()) {
// Upload the new file
$storage = $this->container->get('vich_uploader.storage');
$storage->upload($entity);
// Save the new filename
$om->persist($entity);
$om->flush();
return new RidirectRespone('/');
} @Ocramius Right? |
@Baachi maybe. but still doesn't work in SonataAdminBundle (from the box) :( |
@stfalcon Hm i doesn't work with SonataAdminBundle. |
Maybe you can bake the hack into the sonata code? |
@MisterGlass I thought about it. need to try |
Right now the bundle is coupled to doctrine's lifecycle callback, which means that with no changes to the entity, no callback are called and no upload is triggered. With this coupling there are two options to solve this problem: The second one is my favorite and in the future I would like to loose coupling with persistence layer, but I've not implemented this yet and I'm afraid that I'll not do it soonish. |
I think that if there is no generic fix for the moment then the workaround(s) should be added to the documentation. |
👍 Any chance to work on a PR ? |
Add 'instanceof' check as written here: dustin10#8 (comment) to avoid this issue dustin10#297 (comment)
Say if i have a already existing record, and i'm trying to update it, in case if i ONLY upload file and no other entity properties get changed, the preUpdate event is not called, so the file is not uploaded.
Currently the workaround is to introduce some changes into the entity, before saving it.
The text was updated successfully, but these errors were encountered: