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

Support fk column with code_ or _code

Open adipriyantobpn opened this issue 8 years ago • 8 comments

Q A
Is bugfix? yes
New feature? no
Breaks BC? no
Tests pass? yes
Fixed issues my issues

Add support for foreign key column like code_supplier or supplier_code

adipriyantobpn avatar Sep 02 '17 05:09 adipriyantobpn

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

yii-bot avatar Sep 02 '17 12:09 yii-bot

AFAIK, it is also common to use code as prefix or suffix in foreign key column.

In my case, actually we are need to build REST API for a legacy desktop application. As that application is developed by vendor, we only have authorization to access the database, but not change the database structure (as if changing the foreign key column from supplier_code into supplier_id).

It will be nice, if string code also can be cleaned-up in relation name generation, in addition to string id. As in my case, the database contains almost 300 tables, which always have code prefix or suffix in its foreign key columns.

When does the issue occur?

August 2017, since at that time we'd just start the REST API development.

What do you see? And what was the expected result?

All relation name which it's foreign key has code prefix or suffix, is generated with Code in it. For example for foreign key supplier_code, instead of getting getSupplier() for its relation function name, gii generate getSupplierCode()

adipriyantobpn avatar Sep 03 '17 22:09 adipriyantobpn

OK. Got it. I can't say that using code for the purpose is common.

Instead of introducing hardcoded $string_replacements it worth making a list of replacements a property in model generator and leaving its default value to ['id']. This way there will be no false positives and you'll be able to set your own custom replacements via gii config.

samdark avatar Sep 03 '17 22:09 samdark

@samdark Thank you so much for your feedback. Noted. I'll make public property for that.

adipriyantobpn avatar Sep 09 '17 20:09 adipriyantobpn

Please, write unit tests for this case.

dmirogin avatar Sep 09 '17 20:09 dmirogin

@dmirogin, as a matter of fact, at this time, i don't have much experience for writing unit testing yet. But i would learn it for sure.

adipriyantobpn avatar Sep 12 '17 06:09 adipriyantobpn

Thank you for putting effort in the improvement of the Yii framework. We have reviewed your pull request.

In order for the framework and your solution to remain stable in the future, we have a unit test requirement in place. Therefore we can only accept your pull request if it is covered by unit tests.

Could you add these please?

Thanks!

P.S. If you have any questions about the creation of unit tests? Don't hesitate to ask for support. More information about unit tests

This is an automated comment, triggered by adding the label pr:request for unit tests.

yii-bot avatar Dec 22 '17 20:12 yii-bot

@samdark these changes might have impact on https://github.com/yiisoft/yii2-gii/pull/417 . was looking through the milestone issues and noticed this. Haven't checked it myself to be sure

NickvdMeij avatar Nov 15 '19 10:11 NickvdMeij