У меня есть модель, подобная приведенной ниже:
class Book extends ActiveRecord
{
{ public function getDomain()
{
return $this->hasOne(Domain::className(), ['ID' => 'domainID']);
}
public function getOwnerPerson()
{
return $this->$this->hasOne(Person::className(), ['ID' => 'ownerPersonID']);
}
public function getCreatorUser()
{
return $this->$this->hasOne(User::className(), ['ID' => 'creatorUserID']);
}
public function getUpdaterUser()
{
return $this->$this->hasOne(User::className(), ['ID' => 'updaterUserID']);
}
}
Я создал объект из модели Book следующим образом:
$model=Book::find()->all();
когда я использую $model->domain, все в порядке, но когда я использую $model->ownerPerson, возникает ошибка:
Object of class backend\models\Book could not be converted to string
в чем проблема?






Удалите второй $ this.
return $this->$this->hasOne(Person::className(), ['ID' => 'ownerPersonID']);
to
return $this->hasOne(Person::className(), ['ID' => 'ownerPersonID']);