[solved] Relation not working

[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])


      ->orderBy('callEnd DESC')




   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!


remove ->one() from getContacts()

relation getter should return instance of ActiveQueryInterface so the magic can happen (https://github.com/yiisoft/yii2/blob/master/framework/db/BaseActiveRecord.php#L236)

Thank you so much!!!

Like I suspected: a stupid mistake made by copying a relation getter method where it was a one to many relation and I wanted to fetch only the last entry. Makes sense that in a relation where one entity can be mapped directly to another of the related table the parameter one() is not required .