Skip to content
Snippets Groups Projects
Commit be9f1d24 authored by infotechnohelp's avatar infotechnohelp
Browse files

addAssociatedIds() created

parent 411275bf
No related branches found
No related tags found
No related merge requests found
......@@ -322,6 +322,31 @@ class ModelManager
return $Table->saveOrFail($Entity);
}
public function addAssociatedIds($entityId, $field, $associatedIds)
{
$Entity = $this->find([
'include' => 'first', 'containAll' => true,
], 'Id', $entityId);
$existingAssociatedIds = [];
foreach ($Entity->get($field) as $associatedEntity) {
$existingAssociatedIds[] = $associatedEntity->get('id');
}
$Table = TableRegistry::getTableLocator()->get($this->tableAlias);
$Entity = $Table->patchEntity($Entity, [
$field => [
'_ids' => array_merge($existingAssociatedIds, $associatedIds),
],
]);
return $Table->saveOrFail($Entity);
}
/**
* @param array $ids
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment