0 votes

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

in Solved by (200 points)
recategorized by

1 Answer

0 votes

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

by Skipper developer (141k points)

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

enter image description here

Thanks!

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

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');
    });

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.

Cool thanks so much Ludek,

Will do that and check in ASAP!

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?

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.