Major Bug In Cactiverecord::findall With Join And Limit

This will be a way to reproduce it, I didn’t have time to see how to solve it:

  1. create two tables in mysql:
  • table1: (id - pk autoincrement)

  • table2: (id - pk autoincrement, table1_id - fk)

  1. insert rows, the number of inserted rows is importent:
  • table1:

    INSERT INTO table1 SET id = NULL; execute it 4 times

  • table1:

    INSERT INTO table2 SET table_id = 1; execute it 3 times

    INSERT INTO table2 SET table_id = 2; execute it 2 times

    INSERT INTO table2 SET table_id = 3; execute it 1 time

  1. generate models with gii:

  2. create criteria:

    $criteria = new CDbCriteria();

    $criteria->with = array(

      "table2s" => array(
    
    
          "joinType" => "INNER JOIN",
    
    
      ),
    

    );

4.1) execute criteria with findAll and get the count of rows:

Table1::model()->findAll($criteria); // returns 3 results which is exactly what it should be

4.2) add limit to the criteria and check the new results:

$criteria->limit = 5;


Table1::model()->findAll($criteria); // returns 4 results, it executes two queries, it doesn't take into account joinType

4.3) add limit and together on true to the criteria and check the new results:

$criteria->limit = 5;


$criteria->together = true;


Table1::model()->findAll($criteria); // returns 2 results

Created an issue on github for it: https://github.com/yiisoft/yii/issues/1846