Skip to content
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

Problem with delete when using multiple mappings on one entity #1437

Open
barberob opened this issue Feb 27, 2024 · 0 comments
Open

Problem with delete when using multiple mappings on one entity #1437

barberob opened this issue Feb 27, 2024 · 0 comments

Comments

@barberob
Copy link

barberob commented Feb 27, 2024

Q A
Bundle version 2.3.1
Symfony version 6.4
PHP version 8.2.15

Support Question

Hey ! So i have this entity which can be related to two different other entities

class Photo
{
    // .......
    
    #[ORM\Column(type: 'string', length: 255)]
    private ?string $file;

    #[Vich\UploadableField(mapping: 'signalement_photo', fileNameProperty: 'file')]
    private ?File $uploadFileSignalement = null;

    #[Vich\UploadableField(mapping: 'intervention_photo', fileNameProperty: 'file')]
    private ?File $uploadFileDemandeIntervention = null;

    // .......

    #[ORM\ManyToOne(targetEntity: Signalement::class, inversedBy: 'photos')]
    #[ORM\JoinColumn(name: 'signalement_id', referencedColumnName: 'id')]
    private ?Signalement $signalement = null;

    #[ORM\ManyToOne(targetEntity: DemandeIntervention::class, inversedBy: 'photos')]
    private $demandeIntervention;

It have two different mappings because i need to store it a two different locations depending on the entity it is related to (my config)

    mappings:
        signalement_photo:
            uri_prefix: '%app.path.photoSignalement%'
            upload_destination: photo.storage.signalement
            directory_namer:
                service: vich_uploader.namer_directory_property
                options: { property: 'signalement.id' }
            namer:
                service: Vich\UploaderBundle\Naming\SmartUniqueNamer

        intervention_photo:
            uri_prefix: '%app.path.photoIntervention%'
            upload_destination: photo.storage.intervention
            directory_namer:
                service: vich_uploader.namer_directory_property
                options: { property: 'demandeIntervention.id' }
            namer:
                service: Vich\UploaderBundle\Naming\SmartUniqueNamer

Depending on some logic, i put my uploaded file on the needed UploadableField property, and the bundle handles the job, which is working really great for now.
BUT when i try to delete a photo entity linked to demandeIntervention entity, i have the following error PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL" while trying to traverse path "signalement.id" at property "id".
same thing on the other side when linked to the other entity.
The bundle seems to try to delete the file on both storage, whilst it don't exist in one of the two. How can i prevent this ?
PS: i need this directory structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant