php - Getting unknown empty property after joining relation in search model Yii2 -
i added
$query->joinwith('projectparticipants');
in search model got error:
relation correct , returns data if var_dump in view.
tried well
->leftjoin('project_participants', 'project_participants.user_id = user_cards.id')
but same error. :(
with different relations same problem , in yii debugger queries correct.
where go wrong? empty property?
in model relation looks:
public function getprojectparticipants() { return $this->hasmany(projectparticipants::classname(), ['user_id' => 'id']); }
updated
public function search($params) { $query = usercards::find(); $query->joinwith('projectparticipants'); $dataprovider = new activedataprovider([ 'query' => $query, 'pagination' => array('pagesize' => 45), ]); $this->load($params); if (!$this->validate()) { // uncomment following line if not want records when validation fails // $query->where('0=1'); return $dataprovider; } $query->andfilterwhere([ 'project_participants.proj_id' => $this->projects, ]); $query->andfilterwhere(['ilike', 'name', $this->fullname ])->orfilterwhere(['like', 'surname', $this->fullname ]); return $dataprovider; }
the issue primary key - user_cards model generated db view no pk.
so solution add
public static function primarykey(){ return array('id'); }
in model.
Comments
Post a Comment