Example #1
0
 protected function handleData(array $config)
 {
     foreach ($config['tables'] as $name => $tbl) {
         $this->addTable(Table::createFromStructure($name, $this));
     }
     foreach ($this->tables as $table) {
         if ($extensions = $table->getConfig()['extensions']) {
             foreach ($extensions as $name) {
                 if (!isset($this->extensions[$name])) {
                     throw new \Exception("{$name} 扩展未注册");
                 }
                 $this->extensions[$name]->extendTable($table);
             }
         }
     }
     foreach ($this->tables as $table) {
         if ($belongToNames = $table->getConfig()['belong_to']) {
             foreach ($belongToNames as $name) {
                 $table->addBelongTo($this->getTables()[$name]);
             }
         }
     }
     foreach ($config['many_many'] as $relation) {
         $table = Relation::createManyToManyTable($this->tables[$relation[0]], $this->tables[$relation[1]]);
         $this->addTable($table);
     }
 }