yiisoft / yii2-gii

Yii 2 Gii Extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
202 stars 192 forks source link

[Gii] Model Generator failed to generate relation function name if related model name starts with "Id" #337

Open damiankosiorowski opened 6 years ago

damiankosiorowski commented 6 years ago

What steps will reproduce the problem?

Create a table with name starts with "id" in which one of the fields will be joined by a foreign key with predefined User (ActiveRecord) - i use the advanced template. In Gii, generate a model for table user.

My test DB dump (PostgreSQL!): gii-issue.zip Alternatively, the migration file to a clean DB: m130524_201442_init.zip

What's expected?

It is not expected to trim "id" from the function name. In the below example it should by:

    /** 
     * @return \yii\db\ActiveQuery 
     */ 
    public function getIdeas() { 
        return $this->hasMany(Idea::className(), ['created_by' => 'id']);
    }

What do you get instead?

Ex. function of the relationship:

    /** 
     * @return \yii\db\ActiveQuery 
     */ 
    public function getEas() { 
        return $this->hasMany(Idea::className(), ['created_by' => 'id']);
    }

Additional info

Probably the responsible code: https://github.com/yiisoft/yii2-gii/blob/01883a8df21d0eedd64a5459454d6fc5e2d54bbb/src/generators/model/Generator.php#L690

Q A
Yii version 2.0.13.1
Gii version 2.0.6.0
PostgreSQL 10
PHP version 7.1.1
Operating system Windows 10
samdark commented 6 years ago

Please post DB schema to reproduce the issue. Thanks.

damiankosiorowski commented 6 years ago

DB dump and alternatively migration file have been added in root comment.