/**
* @param string $name
* @throws InvalidArgumentException
* @throws NotImplementedException
* @return EntityBuilder
*/
public function relationBuilder($name)
{
$class = $this->getMetadata();
if (!$class->hasAssociation($name)) {
throw new InvalidArgumentException("Entity {$this->metadata->name} has no association '{$name}'.");
}
if (isset($this->relationBuilders[$name])) {
return $this->relationBuilders[$name];
}
if ($class->isSingleValuedAssociation($name)) {
if (!$this->container->getComponent($name, FALSE)) {
$this->container->addComponent(new Nette\Forms\Container(), $name);
}
$builder = new EntityBuilder($this->container[$name], $this->mapper, $this->controlFactory, $this->em);
if ($this->entity && ($relation = $class->getFieldValue($this->entity, $name))) {
$builder->bindEntity($relation);
} else {
$builder->bindEntityType($class->getAssociationTargetClass($name));
}
return $this->relationBuilders[$name] = $builder;
} else {
throw new NotImplementedException();
}
}