Exemple #1
0
 public function write($model, $name, &$dbValue, $transformatorClass = TransformatorInterface::class)
 {
     if (!$model->{$name}) {
         return;
     }
     $dbRef = DbRefManager::extractRef($model, $name);
     $referenced = $model->{$name};
     $fieldMeta = ManganMeta::create($model)->field($name);
     if ($fieldMeta->dbRef->updatable) {
         DbRefManager::save($referenced, $dbRef);
     }
     $dbValue[$name] = $transformatorClass::fromModel($dbRef, false);
 }
 public function write($model, $name, &$dbValue, $transformatorClass = TransformatorInterface::class)
 {
     $fieldMeta = ManganMeta::create($model)->field($name);
     $dbValue[$name] = $fieldMeta->default;
     // Empty
     if (!$model->{$name}) {
         return;
     }
     // Bogus data
     if (!is_array($model->{$name})) {
         return;
     }
     // Store DbRefs and optionally referenced model
     foreach ($model->{$name} as $key => $referenced) {
         $dbRef = DbRefManager::extractRef($model, $name, $referenced);
         if ($fieldMeta->dbRef->updatable) {
             DbRefManager::save($referenced, $dbRef);
         }
         $dbValue[$name][$key] = $transformatorClass::fromModel($dbRef, false);
     }
 }