public function getForeignKey()
    {
        if ($this->foreignKey !== null) {
            return $this->foreignKey;
        }
        $this->init();
        switch ($this->type) {
            case self::HAS_MANY:
            case self::HAS_ONE:
                return $this->owner->getTableName() . '_' . $this->owner->getPrimaryKey();
            case self::BELONGS_TO:
                return $this->foreign->getPrimaryKey();
            default:
                throw new \Exception(sprintf("Relation type '%s' is not supported.", $this->type));
        }
    }