From d3f15e062faa1f0a8ccee103a2896724bc843e0e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 12 Oct 2023 14:02:35 +1300 Subject: [PATCH] ENH Add new extension hook to update hasmany lists --- src/ORM/DataObject.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index b0514fc7b47..bdbca55ca96 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -1994,6 +1994,10 @@ public function getComponents($componentName, $id = null) $result = HasManyList::create($componentClass, $joinField); } + // Guy note: This mirrors the "updateManyManyComponents" extension hook in getManyManyComponents() + // except it (by necessity) includes the component name as well. + $this->extend('updateComponents', $result, $componentName); + return $result ->setDataQueryParam($this->getInheritableQueryParams()) ->forForeignID($id); @@ -2111,9 +2115,11 @@ public function inferReciprocalComponent($remoteClass, $remoteRelation) $joinField = "{$remoteRelation}ID"; $componentClass = $schema->classForField($remoteClass, $joinField); $result = HasManyList::create($componentClass, $joinField); - return $result + $result = $result ->setDataQueryParam($this->getInheritableQueryParams()) ->forForeignID($this->ID); + // $this->extend('updateComponents', $result, $componentName); // Not sure what the component name should be here though... maybe this isn't doable here? + return $result; } case 'belongs_to': case 'has_many': {