Я столкнулся с неправильным поведением генератора моделей. Опишу ситуацию.
Есть модель Profile (таблица profiles), есть модель ProfileFinances (таблица profile_finances). У Profile есть PK = ['id'], у ProfileFinances PK = ['profile_id','eps','currency']. Связаны они между собой FK как 'profile_id' (ProfileFinances) => 'id' (Profile).
При генерации моделей я получаю в Profile:
Код: Выделить всё
public function getFinances()
{
return $this->hasOne(ProfileFinances::className(), ['profile_id' => 'id']);
}
Глянул логику генератора и обнаружил следующее:
Код: Выделить всё
// Add relation for the referenced table
$hasMany = false;
foreach ($fks as $key) {
if (!in_array($key, $table->primaryKey, true)) {
$hasMany = true;
break;
}
}
То есть мы можем иметь:
[profiles] id=1
[profile_finances] profile_id=1,eps=natural,currency=usd
[profile_finances] profile_id=1,eps=natural,currency=eur
[profile_finances] profile_id=1,eps=natural,currency=gbp
В Yii-1 при той же конфигурации таблиц связи генерировались корректно.