title: Yii2 exist validation rule on database transaction
body: <p>one function in my model use the transaction to save row in two distinct table, table_1 and table_2. In table_2 one foreign key refer to table_1.id and the validation rule, auto generate by gii, is type "exist". When I need to save rows the first step is to begin a database transaction, the second is to set and save a table_1 row and at the end set and save the table_2 rows related with table_1 row, if both insert are ok the transaction are commit else rollback. The problem is when i pass to table_2 the id of table_1 row and the validation fail because the id of table_1 is not valid, but the id is generate in the same script, is this a problem with transaction?</p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>The operations wich generates error:</p>
  
  <pre><code>$order = new OrdersToImport();
  $transaction = OrdersToImport::getDb()-&gt;beginTransaction();
  ... //operations on $order
  if($order-&gt;save()){
     $detail = new OrdersToImportD();
     ... //operations on $detail
     $detail-&gt;id_order = $order-&gt;id;
     if(!$detail-&gt;save()){
        $transaction-&gt;rollback();
        return -1;
     }
  }
  </code></pre>
  
  <p>The code for data validation:</p>
  
  <pre><code>[['id_order'], 'exist', 'skipOnError' =&gt; true, 'targetClass' =&gt; OrdersToImport::className(), 'targetAttribute' =&gt; ['id_order' =&gt; 'id']]
  </code></pre>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>The result of:</p>
  
  <pre><code>if(!$detail-&gt;save()){
      echo "$order-&gt;id";
      echo "$detail-&gt;id_order";
      var_dump($detail-&gt;errors);
      die();
  }
  </code></pre>
  
  <p>is:</p>
  
  <pre><code>187
  187
  array(1) { ["id_order"]=&gt; array(1) { [0]=&gt; string(20) "Id Order is invalid." } }
  </code></pre>