title: Yii2 Active Record using FIND_IN_SET in where clause
body: <p><strong>Product</strong> Table Structure and data - </p>
  
  <blockquote>
    <p>id, product_name, hsn, product_category, product_subcategory, company,
    pic, part_no, min_stock, stock, rate, notes</p>
  </blockquote>
  
  <p>The product_subcategory column contains the values like for eg.</p>
  
  <pre><code>13,14,31,138
  18
  126,140,176,177
  78,79
  </code></pre>
  
  <p>The above numbers are ids of the following table </p>
  
  <p><strong><code>product_subcategory</code></strong> -
  id, subcategory_name</p>
  
  <p>While creating an Invoice I need to search the product by the combination of <code>product_category, product_subcategory, company</code>. </p>
  
  <p>For this, I have the ajax as follows</p>
  
  <pre><code>&lt;?php
  $script2 = &lt;&lt;&lt; JS
  $(document).ready(function () {
  $(document.body).on('change', '#purchaseitems-0-category_id, #purchaseitems-0-model_id, #purchaseitems-0-company_id', function () {
  
      var tt = $("#purchaseitems-0-category_id").val();
      var tt2 = $("#purchaseitems-0-model_id").val();
      var tt3 = $("#purchaseitems-0-company_id").val();
  
      var stuff1 ={'key1': tt ,'key2': tt2, 'key3': tt3};     
      p1();
  });
  });
  
  function p1() {
          var stuff ={'key1':$("#purchaseitems-0-category_id").val(),'key2':$("#purchaseitems-0-model_id").val(), 'key3': $("#purchaseitems-0-company_id").val()};
  
          $.ajax({
              type: "POST",
              url: "http://localhost/yii-application/backend/web/index.php?r=purchase/p1",
              data: {result:JSON.stringify(stuff)},
              success: function (test4) {
  
              var json_obj5 = $.parseJSON(test4);
  
              $('#purchaseitems-0-name_of_product').val(json_obj5.id);
              $('#purchaseitems-0-hsn').val(json_obj5.hsn);
              $('#purchase-taxrate').val(json_obj5.rate);
              $('#purchaseitems-0-part').val(json_obj5.part_no);
                      },
                      error: function (exception) {
                          alert(exception);
                      }                   
  
                  });
      }
   JS;
    $this-&gt;registerJs($script2);
   ?&gt;
  </code></pre>
  
  <p>Now the real code which needs to be changed - </p>
  
  <pre><code>public function actionP1()
      {
          $data2 = Yii::$app-&gt;request-&gt;post('result');
          $data    = $_POST["result"];
          $data    = json_decode("$data", true);
          if (isset($data)) {
              $test = $data;
              $modelfedbkshiprate = \backend\models\Product::find()-&gt;where(['product_category' =&gt; $data["key1"]])-&gt;andWhere(['like' , 'product_subcategory' , $data["key2"]])-&gt;andWhere(['company' =&gt; $data["key3"]])-&gt;one();
          } else {
              $test = "Ajax failed";
          }
          return \yii\helpers\Json::encode($modelfedbkshiprate);          
      }
  </code></pre>
  
  <p>The issue with the above query is the <strong><code>like</code></strong> operator in <code>product_subcategory</code>.
  The <code>like</code> operator searches the <code>id 7</code> instead of <code>78</code> and therefore I end up getting a wrong product. I thought of using <code>FIND_IN_SET</code> but don't know how. </p>
  
  <p>Please suggest an alternate solution to <code>like</code> operator. </p>