Yii2 single search box to search fields from two different tables
<p>I have products table and productlines table. Product has relationship with the productlines. I want to have a single search box and search the fields from product table and fields from productlines table.</p>

<p><strong>My ProductSearch Model</strong></p>

<pre><code>public function search($params)
    {
        $query = Product::find()-&gt;where(['product_id' =&gt; $this-&gt;getProductID()]); 

        // add conditions that should always apply here
         $query-&gt;joinWith('productlines');

        $dataProvider = new ActiveDataProvider([
            'query' =&gt; $query,
        ]);

        $this-&gt;load($params);

        if (!$this-&gt;validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query-&gt;where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query-&gt;andFilterWhere([
            'product_id' =&gt; $this-&gt;product_id,
            'product_region' =&gt; $this-&gt;product_region,
            'product_created' =&gt; $this-&gt;product_created,
            'product_lastchecked' =&gt; $this-&gt;product_lastchecked,
            'sdsref_id' =&gt; $this-&gt;sdsref_id,

        ]);

       // var_dump($this-&gt;getProductID()); exit();
        $query-&gt;andFilterWhere(['like', 'product_name', $this-&gt;product_name])
            -&gt;andFilterWhere(['like','product_id', $this-&gt;product_id])
            -&gt;orFilterWhere(['like', 'product_catalog', $this-&gt;code])
            -&gt;andFilterWhere(['=', 'product_aka', $this-&gt;product_aka])
            -&gt;orFilterWhere(['like', 'internal_code' , $this-&gt;code]);

        return $dataProvider;
    }
</code></pre>

<p>When I do this I get the error:</p>

<pre><code>SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'product_id' in where clause is ambiguous
The SQL being executed was: SELECT COUNT(*) FROM `sim_product` LEFT JOIN `sim_productlines` ON `sim_product`.`product_id` = `sim_productlines`.`product_id` WHERE ((`product_id` IN ('2', '3')) OR (`product_catalog` LIKE '%A%')) OR (`internal_code` LIKE '%A%')
</code></pre>

<p>Can anyone assist me where am I going wrong and what can be the possible solution.</p>

<p>Thanks</p>