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 - ignore behavior properties #372

Open tarranjones opened 6 years ago

tarranjones commented 6 years ago

you cannot have a column called owner_id if you have any behavior attached to your base model

I think it would make more sense to ignore behaviors when creating relation names as some relation names will be illformed.

What steps will reproduce the problem?

run gii model generator with any behavior already attached to the basemodel and have a column name which relation name will share the name of any public behavior property.

Any behavior which inherits from the attributebehavior (timestamp,blamable) will cause the value_id relation name to be getValue0()

the attributesbehavior will cause the order_id relation name to be getOrder0()

and ALL behaviors will cause

owner_id relation name to be getOwner0()

A solution would be to


protected function generateRelationName($relations, $table, $key, $multiple)
... 
//replace
while ($baseModel->hasProperty(lcfirst($name))) {
//with
while ($baseModel->hasProperty(lcfirst($name), true, false)) {

`

example 

### What's expected?

`public function getOwner()`

### What do you get instead?

`public function getOwner0()`

### Additional info
samdark commented 6 years ago

Won't that make behaviors non-functional?