/**
  * Create appropriate instance of RelationSchema based on it's definition provided by ORM Record
  * or manually. Due internal format first definition key will be stated as definition type and
  * key value as record/entity definition relates too.
  *
  * @param RecordSchema $record
  * @param string       $name
  * @param array        $definition
  * @return RelationInterface
  * @throws SchemaException
  */
 public function relationSchema(RecordSchema $record, $name, array $definition)
 {
     if (empty($definition)) {
         throw new SchemaException("Relation definition can not be empty.");
     }
     reset($definition);
     //Relation type must be provided as first in definition
     $type = key($definition);
     //We are letting ORM to resolve relation schema using container
     $relation = $this->orm->relationSchema($type, $this, $record, $name, $definition);
     if ($relation->hasEquivalent()) {
         //Some relations may declare equivalent relation to be used instead, used for Morphed
         //relations
         return $relation->createEquivalent();
     }
     return $relation;
 }