This will be a way to reproduce it, I didn’t have time to see how to solve it:
- create two tables in mysql:
-
table1: (id - pk autoincrement)
-
table2: (id - pk autoincrement, table1_id - fk)
- insert rows, the number of inserted rows is importent:
-
table1:
INSERT INTO
table1
SETid
= NULL; execute it 4 times -
table1:
INSERT INTO
table2
SETtable_id
= 1; execute it 3 timesINSERT INTO
table2
SETtable_id
= 2; execute it 2 timesINSERT INTO
table2
SETtable_id
= 3; execute it 1 time
-
generate models with gii:
-
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