/** * @param string $relation * @param $items */ public function unlink(string $relation, $items) { $relations = $this->mapper->getRelations(); if (!isset($relation[$relation])) { throw new RuntimeException("Unknown relation '{$relation}'"); } /** @var $rel HasOneOrManyThrough */ if (!($rel = $relations[$relation] instanceof HasOneOrManyThrough)) { throw new RuntimeException("Unsupported relation type"); } $rel->unlink($this, $items); }
/** * @param array $results * @return array */ protected function getLazyLoaders(array $results) : array { if (empty($this->with) || empty($results)) { return []; } $loaders = []; $attr = $this->getWithAttributes(); $relations = $this->mapper->getRelations(); $lazyLoader = function (EntityManager $manager, EntityMapper $owner, array $options) { return $this->getLazyLoader($manager, $owner, $options); }; foreach ($attr['with'] as $with => $callback) { if (!isset($relations[$with])) { continue; } $loader = $lazyLoader->call($relations[$with], $this->manager, $this->mapper, ['results' => $results, 'callback' => $callback, 'with' => $attr[$with]['extra'] ?? [], 'immediate' => $this->immediate]); if (null === $loader) { continue; } $loaders[$with] = $loader; } return $loaders; }