Пример #1
0
 public function testIfWillProperlyExtractPkCriteria()
 {
     $model = new WithPlainDbRef();
     $model->stats = new SimplePlainDbRef();
     $ref = DbRefManager::extractRef($model, 'stats');
     $this->assertSame($ref->class, SimplePlainDbRef::class);
     $this->assertInstanceOf(MongoId::class, $ref->pk);
 }
Пример #2
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);
 }
Пример #3
0
 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);
     }
 }