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

Option in Gii to select column of composite foreign key to use for naming getter in model

Open PowerGamer1 opened this issue 9 years ago • 1 comments

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).

PowerGamer1 avatar Jun 12 '15 15:06 PowerGamer1

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.

ljames604 avatar Aug 12 '16 16:08 ljames604