0

我似乎有一个奇怪的问题。使用 Cakephp2 我有 3 个相关的表,例如:

taxon->has genus_id

genus -> has family_id

使用分类模型,我可以按预期正确检索所有数据。现在我想对家庭进行排序。因此,我已将连接手动写入分页数组。如果我添加

'order' => 'Family.family desc'

直接到分页数组,排序按预期工作。但只要参数

sort:Family.family/direction:desc

不是网址的一部分。一旦将这些参数添加到 url,订单部分就会被清空。如何避免这种行为并正确排序结果?

4

1 回答 1

0

The problem seems to be the implementation of Paginator.validateSort. If sort parameters are passed, validate sort checks, if the model has the fields passed. This check is done for the model and for directly (1st level) related models only but not for models with deeper nested associations. I solved the problem by modifying the validateSort method. I've added the (not very elegant) possibility to pass fields followed by an exclamation mark like 'Family.family!'. Such fields are added to the order array even if they fail the check.

Regards

Alex

于 2013-07-13T14:52:46.100 回答