/**
  * {@inheritdoc}
  */
 public function createEquivalent()
 {
     if (!$this->hasEquivalent()) {
         throw new RelationSchemaException("Relation '{$this->record}'.'{$this}' does not have equivalents.");
     }
     //Let's convert to polymorphic
     $definition = [static::EQUIVALENT_RELATION => $this->target] + $this->definition;
     unset($definition[static::RELATION_TYPE]);
     //Usually when relation declared as polymorphic
     return $this->builder->relationSchema($this->record, $this->name, $definition);
 }
Beispiel #2
0
 /**
  * Declare new record relation by it's name and definition. Only unique relations can be added.
  *
  * @see SchemaBuilder::relationSchema()
  * @param string $name
  * @param array  $definition
  * @throws RecordSchemaException
  */
 public function addRelation($name, array $definition)
 {
     if (isset($this->relations[$name])) {
         throw new RecordSchemaException("Unable to create relation '{$this}'.'{$name}', relation already exists.");
     }
     $relation = $this->builder->relationSchema($this, $name, $definition);
     //We can cast relation only if it's parent class has active schema
     if ($this->isActive() && $relation->isReasonable()) {
         //Initiating required columns, foreign keys and indexes
         $relation->buildSchema();
     }
     $this->relations[$name] = $relation;
 }