示例#1
0
 /**
 Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-foreign-key-constraints.html for correct foreign key definition.
 */
 public function buildForeignKeyConstraint(Relationship $rel)
 {
     $schemaClass = $rel['foreign_schema'];
     $fSchema = new $schemaClass();
     $constraint = new Constraint();
     $constraint->foreignKey($rel['self_column']);
     $references = $constraint->references($fSchema->getTable(), (array) $rel['foreign_column']);
     if ($act = $rel->onUpdate) {
         $references->onUpdate($act);
     }
     if ($act = $rel->onDelete) {
         $references->onDelete($act);
     }
     return $constraint;
 }
示例#2
0
 public function index($cols)
 {
     $this->constraints[] = $constraint = new Constraint(NULL, $this);
     $constraint->index($cols);
     return $constraint;
 }
示例#3
0
 public function buildForeignKeys(SchemaInterface $schema)
 {
     return array();
     // FIXME
     $sqls = array();
     if ($this->driver->type == 'sqlite') {
         return $sqls;
     }
     foreach ($schema->relations as $rel) {
         switch ($rel['type']) {
             case Relationship::BELONGS_TO:
             case Relationship::HAS_MANY:
             case Relationship::HAS_ONE:
                 if (isset($rel['self_column']) && $rel['self_column'] != 'id') {
                     $n = $rel['self_column'];
                     $column = $schema->getColumn($n);
                     if ($column->isa == "str") {
                         continue;
                     }
                     $fSchema = new $rel['foreign_schema']();
                     $constraint = new Constraint();
                     $constraint->foreignKey($rel['self_column']);
                     $constraint->reference($fSchema->getTable(), (array) $rel['foreign_column']);
                     // $constraint->onUpdate('CASCADE');
                     // $constraint->onDelete('CASCADE');
                     $sqls[] = $query->toSql($this->driver, new ArgumentArray());
                 }
         }
     }
     return $sqls;
 }
示例#4
0
 public function buildForeignKeyConstraint(Relationship $rel)
 {
     $constraint = new Constraint();
     $constraint->foreignKey($rel['self_column']);
     $fSchema = new $rel['foreign_schema']();
     $references = $constraint->references($fSchema->getTable(), (array) $rel['foreign_column']);
     return $constraint;
 }