You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DataObjectEvent doesn't really work with many_many relation updates because it doesn't trigger a write event.
We managed to partially work around this by putting a custom accessor on the many_many relation and firing a custom event. But that's not really a solution that scales.
publicfunctionProfessionalCategoryPages(int|array$ids = null): Relation
{
$proID = $this->ID;
$callback = function () use ($proID) {
EventService::singleton()->dispatch(newProfessionalCategoryPageAssociation($proID));
};
$relation = $this->getManyManyComponents('ProfessionalCategoryPages', $ids);
// If we are working with an unsaved professional, we might get an UnsavedRelationListif ($relationinstanceof ManyManyList) {
// These callbacks will be fired when an item is removed or added to the relation$relation->addCallbacks()->add($callback);
$relation->removeCallbacks()->add($callback);
}
return$relation;
}
If our many_many relations were handled as many_many_through, we could just target the pivot DataObject. Maybe that's the ultimate recommended solution.
After a quick look at ManyManyList or RelationList or DataList, I couldn't find any hooks that could be targeted to figure when an object is added or removed.
The text was updated successfully, but these errors were encountered:
DataObjectEvent
doesn't really work withmany_many
relation updates because it doesn't trigger a write event.We managed to partially work around this by putting a custom accessor on the many_many relation and firing a custom event. But that's not really a solution that scales.
If our many_many relations were handled as many_many_through, we could just target the pivot DataObject. Maybe that's the ultimate recommended solution.
After a quick look at ManyManyList or RelationList or DataList, I couldn't find any hooks that could be targeted to figure when an object is added or removed.
The text was updated successfully, but these errors were encountered: