Example #1
0
 private function addSchemas($table, $alias, $schema)
 {
     $schemaKey = $alias == '' ? $table : $alias;
     $this->schemas[$schemaKey] = $schema;
     $this->schemas[$schemaKey]['table'] = $table;
     if (isset($schema['hasMany'])) {
         foreach ($schema['hasMany'] as $model) {
             $this->relationships[] = Model::getTableFromModel($model);
         }
     }
     if (isset($schema['hasOne'])) {
         foreach ($schema['hasOne'] as $model) {
             $this->relationships[] = Model::getTableFromModel($model);
         }
     }
     if (isset($schema['belongsTo'])) {
         foreach ($schema['belongsTo'] as $model) {
             $this->relationships[] = Model::getTableFromModel($model);
         }
     }
     if ($table != '') {
         if (isset($schema['foreignKey'])) {
             foreach ($schema['foreignKey'] as $foreignKey => $reference) {
                 $this->foreignKeys[$table][] = array('reference' => Model::getTableFromModel($reference[0]), 'localKey' => $foreignKey, 'referenceKey' => $reference[1]);
                 $this->foreignKeys[Model::getTableFromModel($reference[0])][] = array('reference' => $table, 'localKey' => $reference[1], 'referenceKey' => $foreignKey);
             }
         }
     }
 }