lunar icon indicating copy to clipboard operation
lunar copied to clipboard

Trait HasModelExtending - multiple call Eloquent events

Open lguichard opened this issue 11 months ago • 2 comments

  • Lunar version: 1.x or 0.8
  • Laravel Version: 10.x
  • PHP Version: 8.1

Steps to reproduce :

ModelManifest::register(collect([
    \Lunar\Models\Brand::class => \App\Models\Brand::class
]);

class Brand extends \Lunar\Models\Brand
{

}

Lunar\Models\Brand::create([
   'name'  => 'My brand'
]);

Now, in ActivityLog, Urls we have two same records.

The trait HasModelExtending extends dispatcher of Laravel in registerModelEvent method, but the method listen two times eloquent's events when the model is extending.

In these circumstances, the feature of extending Lunar Model is break and generates strange behaviors. The core doesn't contains any tests about that.

lguichard avatar Feb 26 '24 18:02 lguichard

We are aware of this and the new model extending will resolve this in v1.0.

glennjacobs avatar Feb 26 '24 22:02 glennjacobs

@glennjacobs Yes ! I look forward.

Before launch 1.x version, we should maybe fix the bug with little patch.

lguichard avatar Feb 27 '24 10:02 lguichard

Since this will be solved in v1, I don't anticipate it will be looked at for 0.8 especially because this way of model extending has been completely ripped out.

Closing this issue for now, but if a PR appears it will be considered and can still reference this issue.

alecritson avatar Mar 28 '24 13:03 alecritson