yii2-gii icon indicating copy to clipboard operation
yii2-gii copied to clipboard

Model Generator failed to generate relation function name in camelcase format when column-name in the database is uppercase

Open adipriyantobpn opened this issue 7 years ago • 9 comments

What steps will reproduce the problem?

Column name in the database table is in uppercase format, eg. CUSTOMER_COUNTRY_ID

What's expected?

Generate relation function : public function getCustomerCountry() {...}

What do you get instead?

Relation function will be generated as : public function getCUSTOMERCOUNTRY() {...}

Additional info

Q A
Yii version 2.0.13.1
PHP version 7.1
Operating system Centos 7

adipriyantobpn avatar Dec 26 '17 14:12 adipriyantobpn

Hmm... how should gii behave if the table name is customer_SSID?

samdark avatar Dec 26 '17 15:12 samdark

I think it's better to be generated into getCustomerSsid, then. Or maybe is there any other better format?

adipriyantobpn avatar Dec 26 '17 15:12 adipriyantobpn

I'd expect it to be getCustomerSSID.

samdark avatar Dec 26 '17 15:12 samdark

Hmmm.. if i may ask your opinion, how about CUSTOMER_SSID? Which one that should look better, getCustomerSsid or getCUSTOMERSSID? :)

adipriyantobpn avatar Dec 26 '17 16:12 adipriyantobpn

That's the problem. DB conventions may be different. Either we should introduce different schemas to select or not to change current behavior.

samdark avatar Dec 26 '17 16:12 samdark

Agreed..

Hmm.. Is there a way to customize the current behavior? Or maybe any plan to provide a way to customize it?

For example: If the column-name is in lower-case, current camelizing behavior is just fine. If it is in upper-case, we can set generated string to be camelized after it is turned to lowercase first. If it is in mixed-case, only first character is turned to uppercase (in this case, i just tested that current behavior is working just as expected).

For the sake of clean function naming though.

adipriyantobpn avatar Dec 26 '17 16:12 adipriyantobpn

Agree. It makes sense the way you've described it.

samdark avatar Dec 26 '17 18:12 samdark

I'd expect it to be getCustomerSSID.

If you expect getCustomerSSID your column should be named customer_S_S_I_D_id. getCustomerSsid looks perfectly valid for me.

rob006 avatar Dec 26 '17 21:12 rob006

This is very similar to #366. But there we have a new form option to enable PSR names. It was not set default for BC. Should it be done here too? I mean, should we have a optional feature or should it be default? I fear to have too much options in gii model generator form.

sdlins avatar Jun 13 '18 12:06 sdlins