Exemplo n.º 1
0
 /**
  * Updates schema of selected data source to contain definition for current
  * model's set.
  *
  * @param connection $source data source to use
  * @throws datasource_exception on updating schema failed
  * @throws model_exception on incomplete/invalid schema definition
  */
 public static function updateSchema(connection $source)
 {
     $dataSet = static::$set_prefix . static::$set;
     if (!$source->exists($dataSet)) {
         if (!$source->createDataset($dataSet, static::getSchema(), static::$id)) {
             throw new datasource_exception($source, 'updating schema failed');
         }
     }
     foreach (static::$relations as $name => $definition) {
         $nextModel = static::relation($name)->nodeAtIndex(1)->getModel();
         if ($nextModel->isVirtual()) {
             $nextModel->declareInDatasource($source);
         }
     }
 }