Question: Let's Say i have two tables,
Table1 Table2
-authorId -username
As of now my sql query on search model looks like this,
->andFilterWhere(['"Table1"."authorId"' => $this->authorName]);
It only helps to search and filter using the authorID.
Expected Result I would like to search based on the authorname instead of authorId.
I faced similar difficulty in reflecting data in view but i was able to fix it with following getter function in base model.
public function getAuthorName() {
return $this->author->username;
}
Thanks in Advance,
First, add a custom attribute to your search model
define a relation to your
author
table inside the modelin your
gridview
replace theauthorId
column withand use the following to compare
and yes make sure you join you searchmodel query with the
author
table in the start of search functionAssuming
authorId
is a FK totable2
, and you have previoulsy joinedtable2
totable1
, you can do the following: