tighten / parental

Use single table inheritance in your Laravel app
MIT License
1.36k stars 98 forks source link

Double events when registering in parent boot #37

Closed kbond closed 5 years ago

kbond commented 5 years ago

When registering an event in a parent's boot method. It is triggered twice if the parent was booted first in the same process.

For instance, with a Page model that has a Product child and a created event registered in Page::boot():

Product::create() // triggers the created event once as expected

(another process)

Page::create() // triggers the created event once as expected
Product::create() // triggers the created event twice (not expected)

I believe this was introduced in #26.

dallincoons commented 5 years ago

@kbond Do you have an observer on the Page model and the Product model? Because then in your second example the expected behavior is that it calls an observer method three times, two times in the parent observer and one in the child, per https://github.com/tightenco/parental/blob/master/tests/Features/ParentsObserveChildrenTest.php#L15

kbond commented 5 years ago

No observers at all. Just static::created(function () {}) in Page::boot()

dallincoons commented 5 years ago

@kbond ah yep, I'm seeing the same thing you're describing. Looks like it's only an issue when registering observer events in boot

kbond commented 5 years ago

I added a PR with a failing test (#40) to better demonstrate the problem.

calebporzio commented 5 years ago

Should be fixed in the aforementioned PR