Example #1
0
 /**
  * Test the validity of a model
  * @final
  * @param Cognosys\Model $model
  * @return bool
  */
 protected final function valid(Model $model)
 {
     $model->validate();
     $errors = Validator::get();
     AlertManager::import($errors);
     $metadata = $this->getClassMetadata(get_class($model));
     foreach ($metadata->associationMappings as $assoc) {
         $method = TextUtil::camelize($assoc['fieldName']);
         if (is_numeric($model->{$method}()) && $model->{$method}() > 0) {
             // transform the identifier to the entity
             $model->{$method}($this->getReference($assoc['targetEntity'], $model->{$method}()));
             $this->persist($model->{$method}());
         }
     }
     return empty($errors);
 }