[Closed] onDelete in Many-To-Many relation

0 votes
asked Mar 2, 2020 in Solved by cent89 (200 points)
recategorized Aug 14, 2020 by ludek.vodicka

Hi,
in a Many-to-many relationship, how I can set the 'on delete' and 'on update' properties?
Thanks

1 Answer

0 votes
answered Mar 2, 2020 by ludek.vodicka Skipper developer (140,450 points)

Hello,

I believe you're asking how to do that in Doctrine2 ORM, right?

If so, you need to select one of two associations leading from MN entity and configure on-delete and on-update.

Each direction is configured independently.

enter image description here

commented Mar 2, 2020 by cent89 (200 points)

Hi,
the project is in Laravel.
In ORM Properties I haven't the on-delete field...

enter image description here

Thanks!

commented Mar 2, 2020 by ludek.vodicka Skipper developer (140,450 points)

Oh, ok. Sorry.

Regarding Laravel, there is no mention about on-update/on-delete for many-to-many relation in Laravel Eloquent documentation. Because of that, we didn't implement it.

In case that Laravel supports it, please post here any documentation link or the other source based on what we can implement it.

Thanks

commented Oct 27, 2021 by ryanhungate (160 points)

Hey Ludek,

I second this problem... the onDeleteCascades are not limited to this relation type - matter of fact we're blocked in our project due to this limitation without doing a lot of workarounds every time we update a revision... so please add this feature just as you do in the "local" relation model which does this just fine.

Your skipper produces this:

 Schema::table('tax_order_detail', function (Blueprint $table) {
        $table->foreign('order_detail_id')->references('id')->on('order_details');
        $table->foreign('tax_id')->references('id')->on('taxes');
    });

But should actually be THIS for us.

Schema::table('tax_order_detail', function (Blueprint $table) {
        $table->foreign('order_detail_id')->references('id')->on('order_details')->onDelete('cascade');
        $table->foreign('tax_id')->references('id')->on('taxes')->onDelete('cascade');
    });
commented Oct 27, 2021 by ludek.vodicka Skipper developer (140,450 points)

No problem at all. This should be already implemented in the latest beta:

https://www.skipper18.com/support/402/downloads-skipper-beta

Please test it and let me know.

commented Oct 27, 2021 by ryanhungate (160 points)

Cool thanks so much Ludek,

Will do that and check in ASAP!

commented Oct 28, 2021 by ryanhungate (160 points)

Hey Ludek,

So we're seeing the option in Skipper to configure the cascading - but when you export the model, it's not actually being set in the migration file. :/

Did you guys test that part? Actually see the ->cascadeOnDelete() method being appended on the migration? Is there another step we're missing?

commented Oct 28, 2021 by ludek.vodicka Skipper developer (140,450 points)

Ofc we tested it. And fix was probably also confirmed by another customer when we did that.

But there are so many combinations that we can't test everything. So in case that this doesn't work for you, please prepare a minimal test case and send it to [email protected] so we can replicate it here and fix it.

...