Closed AliSuliman01 closed 3 years ago
Are you able to clarify how it’s not working?
ya sure... here is products migration :
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->softDeletes();
});
}
and here is product filter categories migration :
public function up()
{
Schema::create('product_filter_categories', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('category_id');
$table->unsignedBigInteger('product_id');
$table->foreign('product_id')
->references('id')
->on('products')
->onDelete('cascade');
$table->foreign('category_id')
->references('id')
->on('categories')
->onDelete('cascade');
$table->timestamps();
$table->softDeletes();
});
}
when i soft delete a product's recored as following :
$product = Product::find($product->id);
$product->delete();
related recoreds at product_filter_categories table are not soft deleted !
edit 1 : and here is ProductFilterCategory model :
class ProductFilterCategory extends Pivot
{
use HasFactory, SoftDeletes;
protected $table = "product_filter_categories";
protected $guarded = [
'id',
'created_at',
'updated_at',
'deleted_at',
];
}
Hi...
I need this package, but if this is true, I'm worried.
I've done some investigation and it looks like the delete
method of the AsPivot
trait is called, rather than the one provided by SoftDeletes
for the pivot model (via $model->pivot->delete()
).
It must have something to do with the way we're calling delete, though, because the soft delete works if you call it on the pivot model directly. Needs some more investigation, but would appreciate any help you can offer on that front.
I've never used soft deletes on the pivot table personally, so no direct experience with it.
I've done some investigation and it looks like the
delete
method of theAsPivot
trait is called, rather than the one provided bySoftDeletes
for the pivot model (via$model->pivot->delete()
).It must have something to do with the way we're calling delete, though, because the soft delete works if you call it on the pivot model directly. Needs some more investigation, but would appreciate any help you can offer on that front.
I've never used soft deletes on the pivot table personally, so no direct experience with it.
Nice to meet you.
The prerequisites for this issue seem odd.
In order to soft delete from the pivot table, the pivot model must be changed to extend the 'Model' class, not the 'Pivot' class.
So, from my point of view, it doesn't appear to be a problem.
I've done some investigation and it looks like the
delete
method of theAsPivot
trait is called, rather than the one provided bySoftDeletes
for the pivot model (via$model->pivot->delete()
). It must have something to do with the way we're calling delete, though, because the soft delete works if you call it on the pivot model directly. Needs some more investigation, but would appreciate any help you can offer on that front. I've never used soft deletes on the pivot table personally, so no direct experience with it.Nice to meet you.
The prerequisites for this issue seem odd.
In order to soft delete from the pivot table, the pivot model must be changed to extend the 'Model' class, not the 'Pivot' class.
So, from my point of view, it doesn't appear to be a problem.
I don't expect this to be a problem with this package.
For artifact creators to use "use SoftDeletes", artifact creators need to change the inheritance of the pivot model.
https://laravel.com/docs/8.x/eloquent-relationships#defining-custom-intermediate-table-models
I expected a problem with this package. So I implemented the delete function myself. Interestingly, it's identical to your code.
I will use this package. If there are any problems, I will contribute a pull request.
Right, there’s even a note that specifically says you can’t use SoftDeletes
on a model extending the Pivot
relation, you need to extend from Model
.
the package works perfect for one-to-many relationship, but when it comes to many-to-many relationship it's not working here is my code :
is it a wrong in my code or this package don't support many-to-many relation ?