[font="Arial"][size="2"]Hey advanced devs, i got a problem with a yii2 relation in a model.
The model is named "Calls"; one call entity always contains the information (stored in the attribute "idContact"), which contact from the "Contacts" model was called.
Invalid Parameter yii\base\InvalidParamException
app\models\Calls has no relation named "contact".
I call the relation like this with "with":
/**
* All calls of an agent today
* @param $idUser
* @return array \yii\db\ActiveRecord[]
*/
public static function arrCallsTodayOfAgent($idUser)
{
$datetime =new \DateTime();
$datetime = $datetime->format('y-m-d');
$callsTodayOfAgent = self::find()
->where(['idUser' => $idUser])
->andWhere(['like', 'callEnd', $datetime])
->with('contact')
->orderBy('callEnd DESC')
->limit(10)
->asArray()
->all();
return $callsTodayOfAgent;
}
In the same model I have the function
/*
* Relation to the contact who got called
*/
public function getContact()
{
return $this->hasOne(Contacts::className(), 'id' => 'idContact'])->one();
}
I do not know, why my relation is not found. I use several relations in other models without any issue and I see no difference. Other relations of this model are accessible neither from arrCallTodayOfAgent($idUser). This has to be a trivial misstake of mine which I am just not capable of seeing myself.
Thank you for any help in advance!
[/size][/font]