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

[SoftDeleteable] Form with deleted relation exception #1759

Closed
Glideh opened this issue Mar 8, 2017 · 8 comments
Closed

[SoftDeleteable] Form with deleted relation exception #1759

Glideh opened this issue Mar 8, 2017 · 8 comments

Comments

@Glideh
Copy link

Glideh commented Mar 8, 2017

Trying to display a form bound to an objectA linked to a soft deleted objectB selectable in a list will throw an exception.

Let's see some code:

class EntityA
{
    /**
     * @ORM\ManyToOne(targetEntity="EntityB")
     */
    private $entityB
//...
/**
 * ...
 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
 */
class EntityB
//...
class EntityAType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('entityB');
//...
$objectA->setEntityB($objectB);
$em->delete($objectB);
$this->createForm(EntityAType::class, $objectA)

Gives

Entity of type 'AppBundle\Entity\EntityB' for IDs id(42) was not found

... since the transformer can't get objectB anymore

Is there a simple way to silently show the form just without objectB in the list ?
I need this behavior in many places of my current application.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 8, 2017

Hi, extensions do not provide ways to deal with relations of softdeleted items, it simply would be too cumbersome to implement and would not cover all possible options. I've seen someone has made a bundle to deal with it in some way. But I personally haven't used this extension and manually managed softdeletion.

@Glideh
Copy link
Author

Glideh commented Mar 9, 2017

Don't hesitate to point me the bundle if you remember.
This seems to be linked to #1427
I'll also try to use EAGER fetch or exception when softdeleting parent objects

@Glideh Glideh changed the title [SoftDeleteable] Form ChoiceToValueTransformer exception [SoftDeleteable] Form with deleted relation exception Mar 9, 2017
@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 9, 2017

see #505

@Glideh
Copy link
Author

Glideh commented Mar 9, 2017

Thank you, so a SET NULL with SoftDeleteableListenerExtensionBundle would be close to what I need.
I would have to define the inverse relations when needed though (here EntityB.entityA as OneToMany).
I'll try that.

@maxblache
Copy link

maxblache commented Nov 30, 2018

@Glideh Did that solve your problem ? I got same issue but can't get through. It seems that it works only if form is linked to the 'One' entity in the ManytoOne relation. Which is not my case...

@Glideh
Copy link
Author

Glideh commented Dec 3, 2018

I did finally not use this softdelete extension.
I managed it with a simple base repository with a filter (ex/in)cluding objects marked as deleted in the query builder.

@maxblache
Copy link

ok, thanks. I've finally chosen to use the 'fetch=eager' solution to bypass the filter

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

4 participants