Askedio / laravel-soft-cascade

Cascade Delete & Restore when using Laravel SoftDeletes
https://medium.com/asked-io/cascading-softdeletes-with-laravel-5-a1a9335a5b4d
MIT License
705 stars 63 forks source link

Fixes cascade deleting models that use eager loading #104

Closed Upperfoot closed 5 years ago

Upperfoot commented 5 years ago

Because of line 203 asking for just the ID (Key Name) column (Line 208) it will cause eager loads to fail if a relationship that depends on a column that is missing completely from that model.

An example pseudo model structure

class Post {
     $with = ['type']; // Eager load by default
     function type() {
           $this->belongsTo(PostType::class, 'type_id');
     }
}

If type_id is missing from the model, eager loading will fail.

What I am doing is disabling eager loading for this particular query as it's not needed, via setEagerLoads([]);

maguilar92 commented 5 years ago

@Upperfoot Thanks to contribute with package. Could you create test/s to cover this case of use?

Upperfoot commented 5 years ago

@maguilar92 I could, all I would need to break this entire package is add a $with declaration pointing to a BelongsTo relation on any of the test models.