Revert "Revert "patch to avoid wrong join in pagination.""

This reverts commit 7d320edcf746eb1c93c8ab700bd2d16ade5e63fb.