-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add other model's relation events #4561
Comments
Please only use GitHub Issues for feature requests if you are using it as a pre-Pull Request collaboration tool. If you aren't planning on implementing it yourself, then it would be better suited being asked for on one of these channels: Forum: http://octobercms.com/forum The support demand for October is increasing, while the available time the founders have to give remains the same. Feature requests are by default the lowest priority for us, as we don't have time to implement everyone's suggestions by ourselves. However there are ways you can help:
|
More detailsJust now we have this 4 relation events for BelongsToMany relation:
But other events and relations are not covered. This is table of full covered relations and their events: hasOneOrMany
belongsTo
belongsToMany
For polymorphic relations is situation the same. MorphToMany a MorphedByMany like belongsToMany. Why?I think this feature was incomplete. BelongsToMany event was covered only for attaching and detaching, but belongsTo not. My usecases need especially trigger event when model is created from side of parent (hasOne, hasMany), but this is not covered at all. Adding this events help to make code more clarity on side Model relations instead of controller side. |
@Rike-cz could you post an example of how you plan on using these events in your project / plugins? |
In model constructor for example:
|
This issue will be closed and archived in 3 days, as there has been no activity in the last 30 days. If this issue is still relevant or you would like to see action on it, please respond and we will get the ball rolling. |
After the time I decided to make revision of this conceptual enhancement. For me looks before/after create/update/save events redundant now, because can be simply handle by relationed model as usual. Only these events looks as benefit for handling birth and death of relationships: BelongsToMany
BelongsTo, MorphTo
HasOneOrMany, AttachOneOrMany, MorphOneOrManyAnd here is the question. To have inversional events for these relationships or to call inversional counterparts above when needed? When needed means add/remove methods where relationship arises.
Handling pivots is possible via handling pivot models as needed (MorphPivot will come soon). I think there are no additional events needed. |
Why are there three different types of events instead of just one? |
They are called by their callers. Existing BelongsToMany {after|before}Attach event was also called by the method, that caused relation change. Can you elaborate your purpose? I am not sure if I understand. |
I mean why wouldn't the event name just be |
Are you saying that Laravel already has beforeAttach() model methods that are called in those cases? |
Not Laravel. OctoberCMS has this event: https://octobercms.com/docs/api/model/relation/afterattach. I thought that good way is to respect naming convention, so Model::belongsTo()::associate() fires event with this name but it is not necessary. This Laravel package was my earlier inspiration: https://github.com/chelout/laravel-relationship-events. |
hmm, fair enough. I'm fine with those names then. |
By now there are only attach/detach events for BelongsToMany relation. Adding other events will make using OctoberCMS more comfortable. Good example there: https://github.com/chelout/laravel-relationship-events.
Please add this feature request to bounty.
The text was updated successfully, but these errors were encountered: