示例#1
0
 public final function setForeignKeyObject(ForeignKey $foreign_key) : TableInterface
 {
     if ($this->isImmutable()) {
         throw SchemaException::immutable(static::class);
     }
     if ($this->hasForeignKey($foreign_key->getName())) {
         throw SchemaException::foreignKeyAlreadySet(static::class, $foreign_key->getName());
     }
     $missing = array_diff($foreign_key->getColumns(), array_keys($this->getColumns()));
     if ($missing !== []) {
         throw TableException::columnNotSet(static::class, implode(', ', $missing));
     }
     $this->foreign_keys[$foreign_key->getName()] = $foreign_key;
     if (!$this->hasIndexWithColumns(...$foreign_key->getColumns())) {
         $this->setIndexObject(new Index($foreign_key->getName(), ...$foreign_key->getColumns()));
     }
     return $this;
 }