/** * Part of the store() functionality. * Handles all new additions after the bean has been saved. * Stores addition bean in own-list, extracts the id and * adds a foreign key. Also adds a constraint in case the type is * in the dependent list. * * @param OODBBean $bean bean * @param array $ownAdditions list of addition beans in own-list * * @return void * * @throws Security */ private function processAdditions($bean, $ownAdditions) { $beanType = $bean->getMeta('type'); $cachedIndex = array(); foreach ($ownAdditions as $addition) { if ($addition instanceof OODBBean) { $myFieldLink = $beanType . '_id'; $alias = $bean->getMeta('sys.alias.' . $addition->getMeta('type')); if ($alias) { $myFieldLink = $alias . '_id'; } $addition->{$myFieldLink} = $bean->id; $addition->setMeta('cast.' . $myFieldLink, 'id'); $this->store($addition); if (!$this->isFrozen) { $additionType = $addition->getMeta('type'); $key = $additionType . '|' . $beanType . '>' . $myFieldLink; if (!isset($cachedIndex[$key])) { $this->writer->addIndex($additionType, 'index_foreignkey_' . $additionType . '_' . $beanType, $myFieldLink); $isDep = $bean->getMeta('sys.exclusive-' . $additionType); $this->writer->addFK($additionType, $beanType, $myFieldLink, 'id', $isDep); $cachedIndex[$key] = TRUE; } } } else { throw new RedException('Array may only contain OODBBeans'); } } }