Did I miss something or is it impossible to set a related model directly in yii\db\ActiveRecord? For example:
namespace app\models;
use yii\db\ActiveRecord;
use Person;
class EmailAddress extends ActiveRecord
{
public function getPerson()
{
return $this->hasOne(Person::className(), ['personId' => 'id']);
}
public function setPerson(Person $person)
{
// What to do here???
}
}
I know there’s yii\db\ActiveRecord::link() but it triggers an immediate database call which I want to avoid. My actual scenario is replacing related models with mock objects in tests but there are many other valid use cases for setting related objects directly.