An Unexplainable Issue With Pagination Pagesize

Hello fellow Yii’ers.

Without any clear reason I’m experiencing that a particular admin page is showing only half of what I set as PageSize.

If the PageSize is set to 10 it shows 4 of 10 (Displaying 1-4 of 10 results)

If set to 20 it shows 10.

Here is the code from Search()




public function search() {

		$criteria = new CDbCriteria;


		$criteria->with = [

			'institution' => [

				'alias' => 'institution',

			],

			'user' => [

				'alias' => 'user',

				'with' => [

					'profile' => [

						'alias' => 'profile',

					],

				],

			],

			'employeeType' => [

				'alias' => 'employeeType'

			],

			'employeeTitle' => [

				'alias' => 'employeeTitle'

			],

			'departmentEmployees' => [

				'alias' => 'departmentEmployees',

				'together' => TRUE,

				'with' => [

					'department' => [

						'alias' => 'department',

					]

				]

			],

		];


		$criteria->addCondition('t.institution_id',  $this->currentUserInfo['employee']['institution_id']);

		$criteria->addSearchCondition('t.institution.name', $this->institution_id);

		$criteria->addSearchCondition('concat(profile.firstname, " ", profile.lastname)', $this->id);

		$criteria->addSearchCondition('department.name', $this->department_name);

		$criteria->addSearchCondition('alias', $this->alias);


		return new CActiveDataProvider($this, [

			'criteria' => $criteria,

			'sort' => [

				'defaultOrder' => 'concat(profile.firstname, " ", profile.lastname) asc',

				'attributes' => [

					'id' => [

						'asc' => 'concat(profile.firstname, " ", profile.lastname)',

						'desc' => 'concat(profile.firstname, " ", profile.lastname) desc',

					],

					'department_name' => [

						'asc' => 'department.name',

						'desc' => 'department.name desc',

					],

				//'*',

				],

			],

			'pagination' => [

				'PageSize' => 10,

			],

		]);

	}



Here is the Admin part




$this->widget('bootstrap.widgets.TbGridView', [

	'id' => 'employee-grid',

	'dataProvider' => $model->search(),

	'filter' => $model,

	'columns' => [

		[

			'name' => 'id',

			'type' => 'raw',

			'value' => function($data) {

			return CHtml::tag('strong', [], $data->getFullname()) . $data->ibgFolder->coverImageLink;

		},

		],

		[

			'name' => 'department_name',

			'type' => 'raw',

			'value' => function($data) {

			return $data->getDepartmentsList();

		}

		],

		[

			'class' => 'bootstrap.widgets.TbButtonColumn',

		],

	],

]);



Any suggestion is appreciated.

Many thanks in advance

this is because you join with HAS_MANY/MANY_MANY relations. in that case n rows is fetched from db, but then they are combined and merged.

in other words - when you have table A and B and record "a" in table A and records "b1", "b2" in table B which reference table A then:

when you query A with B (together = true) you get carthesian join:

a b1

a b2

(two rows) then Yii merges this into:

a (b1, b2)

but limit is applied on query, not merged results. is that clear?

Hello,

And thank you so much for the explanation. I get it now. :)