Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
damiankosiorowski opened this issue Feb 22, 2018 · 2 comments
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@damiankosiorowski
Copy link

damiankosiorowski commented Feb 22, 2018

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:

if (!empty($key) && strcasecmp($key, 'id')) {

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 samdark added type:bug Bug status:to be verified Needs to be reproduced and validated. labels Feb 22, 2018
@samdark
Copy link
Member

samdark commented Feb 22, 2018

Please post DB schema to reproduce the issue. Thanks.

@samdark samdark added this to the 2.0.7 milestone Feb 22, 2018
@damiankosiorowski
Copy link
Author

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

@samdark samdark modified the milestones: 2.0.7, 2.0.8 Apr 30, 2018
@samdark samdark modified the milestones: 2.0.8, 2.1.1 Dec 8, 2018
@samdark samdark modified the milestones: 2.1.1, 2.1.2 Aug 13, 2019
@samdark samdark removed this from the 2.1.2 milestone Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

2 participants