yii2-gii
yii2-gii copied to clipboard
Option in Gii to select column of composite foreign key to use for naming getter in model
Lets say I have a table Project with a composite foreign key with two columns (account_id,created_by) to another table User. In such a case Gii uses the name of the FIRST column of composite key for a getter in the Project class:
public function getAccount1()
{
return $this->hasOne(User::className(), ['account_id' => 'account_id', 'id' => 'created_by']);
}
But in reality the getter needs to be named after the LAST column in the composite foreign key:
public function getCreatedBy()
{
return $this->hasOne(User::className(), ['account_id' => 'account_id', 'id' => 'created_by']);
}
So it would be nice to have an option in Gii interface to select which column of composite foreign key to use for naming getters (first or last).
I would also like to see the ability to add composite foreign keys in the migration scripts. As far as I know this functionality does not exist.