mootensai\enhancedgii\BaseGenerator::generateRelationName PHP Method

generateRelationName() protected method

Generate a relation name for the specified table and a base name.
protected generateRelationName ( array $relations, yii\db\TableSchema $table, string $key, boolean $multiple ) : string
$relations array the relations being generated currently.
$table yii\db\TableSchema the table schema
$key string a base name that the relation name may be generated from
$multiple boolean whether this is a has-many relation
return string the relation name
    protected function generateRelationName($relations, $table, $key, $multiple)
    {
        //        print_r($key);
        static $baseModel;
        if ($baseModel === null && isset($this->baseClass)) {
            $baseClass = $this->baseClass;
            $baseModel = new $baseClass();
        }
        if (!empty($key) && substr_compare($key, 'id', -2, 2, true) === 0 && strcasecmp($key, 'id')) {
            $key = rtrim(substr($key, 0, -2), '_');
        } else {
            if (!empty($key) && substr_compare($key, 'id', 0, 2, true) === 0 && strcasecmp($key, 'id')) {
                $key = ltrim(substr($key, 2, strlen($key)), '_');
            }
        }
        if ($multiple) {
            $key = Inflector::pluralize($key);
        }
        $name = $rawName = Inflector::id2camel($key, '_');
        $i = 0;
        while (isset($baseModel) && $baseModel->hasProperty(lcfirst($name))) {
            $name = $rawName . $i++;
        }
        while (isset($table->columns[lcfirst($name)])) {
            $name = $rawName . $i++;
        }
        while (isset($relations[$table->fullName][$name])) {
            $name = $rawName . $i++;
        }
        return lcfirst($name);
    }