Код: Выделить всё
public function getPerson() { // в модели Account
return $this->hasOne(Person::class, ['id' => 'person_id']);
}
Код: Выделить всё
public function beforeSave($insert) { // в модели Account
if ($insert)
$this->link('person', new Person);
return parent::beforeSave($insert);
}
Код: Выделить всё
if ($insert) {
$person = new Person;
$person->save();
$this->link('person', $person);
}