-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ObservedBy on parent model classes #53579
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
Hey there! Could we get a test for this? Also should it keep going back up the tree in case there are multiple extensions? |
@taylorotwell You're too fast! :) I added another couple of commits after the initial draft pull request. These address the tree traversal issue you're asking about. Will add a test ASAP. |
@taylorotwell Added a test. (Sorry about the sloppy commit history.) |
Thanks! |
This is a breaking change for me as I have a parent observer that creates polymorphic relationships, the grandchild model can't have these and doesn't have a morph map value. Here is another example: class MessageObserver
{
public function created(Message $message)
{
// send to all users
}
}
#[ObservedBy(MessageObserver)]
class Message extends Model {}
class AdminMessage extends Message {} Previously, creating an This PR takes away the granularity of adding the Should we check for |
@patrickomeara hmm, tough call. I would say that the change we made is in line with the way other things work in the framework in general. For example, putting ShouldQueue on a parent class and dispatching the child class to the Bus will in fact queue it. Same with mail, notifications, etc. Or, registering a container callback to a parent type will get called for child types. |
@taylorotwell OK, that makes sense. Staying in line across the framework is the correct approach. In my case I will remove the inheritance and use the same table name. It's a hangover from a long time ago and feels like an anti-pattern now. |
When an Eloquent model extends another Eloquent model, the check for the ObservedBy attribute only considers the class itself. Any observers registered in the parent model are ignored.
This change adds support for the ObservedBy attribute in parent classes and traverses the hierarchy until the top Model class is reached.