Пример #1
0
 /**
  * @depends testNewRecordNestedSave
  * @param Record $it
  */
 public function testRecordSave(Record $it)
 {
     $this->handleDebug(__FUNCTION__);
     $authorName = 'G. Orwell';
     $bookAuthorId = 2;
     $it->name = $authorName;
     $it->book->authors_id = $bookAuthorId;
     $it->save();
     $it->book->save();
     $this->assertEquals([$authorName, $bookAuthorId], [$it->name, $it->book->authors_id]);
 }
Пример #2
0
 /**
  * @param \Enjoin\Record\Record $Record
  * @param array $volume
  * @return mixed
  */
 private static function savePersistent(Record $Record, array $volume)
 {
     $scope = $Record->scope();
     $Model = Enjoin::get($scope->modelName);
     $DB = $Model->connection();
     return $DB->transaction(function () use($volume, $scope, $Model) {
         if (isset($volume['id']) && $volume['id'] === $scope->id) {
             unset($volume['id']);
         }
         $Model->queryBuilder()->where('id', $scope->id)->take(1)->update($volume);
         // id can be changed
         $Model->cache()->flush();
         return isset($volume['id']) ? $volume['id'] : $scope->id;
     });
 }