getModel() public method

Returns entity model.
public getModel ( boolean $need = true ) : Nextras\Orm\Model\IModel
$need boolean
return Nextras\Orm\Model\IModel
 /**
  * @return IRepository
  */
 protected function getTargetRepository()
 {
     if (!$this->targetRepository) {
         $this->targetRepository = $this->parent->getModel()->getRepository($this->metadata->relationship->repository);
     }
     return $this->targetRepository;
 }
Beispiel #2
0
 protected function createEntity($value, $allowNull)
 {
     if ($value instanceof IEntity) {
         if ($model = $this->parent->getModel(false)) {
             $repo = $model->getRepository($this->metadata->relationship->repository);
             $repo->attach($value);
         } elseif ($model = $value->getModel(false)) {
             $repository = $model->getRepositoryForEntity($this->parent);
             $repository->attach($this->parent);
         }
     } elseif ($value === null) {
         if (!$this->metadata->isNullable && !$allowNull) {
             throw new NullValueException($this->parent, $this->metadata);
         }
     } elseif (is_scalar($value)) {
         $value = $this->getTargetRepository()->getById($value);
     } else {
         throw new InvalidArgumentException('Value is not a valid entity representation.');
     }
     return $value;
 }
Beispiel #3
0
 protected function createEntity($value, $forceNULL)
 {
     if ($value instanceof IEntity) {
         if ($model = $this->parent->getModel(FALSE)) {
             $repo = $model->getRepository($this->propertyMeta->relationshipRepository);
             $repo->attach($value);
         } elseif ($model = $value->getModel(FALSE)) {
             $repository = $model->getRepositoryForEntity($this->parent);
             $repository->attach($this->parent);
         }
     } elseif ($value === NULL) {
         if (!$this->propertyMeta->isNullable && !$forceNULL) {
             $class = get_class($this->parent);
             throw new InvalidArgumentException("Property {$class}::\${$this->propertyMeta->name} is not nullable.");
         }
     } elseif (is_scalar($value)) {
         $value = $this->getTargetRepository()->getById($value);
     } else {
         throw new InvalidArgumentException('Value is not a valid entity representation.');
     }
     return $value;
 }