首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >命令条件在cakephp 3树行为中不起作用

命令条件在cakephp 3树行为中不起作用
EN

Stack Overflow用户
提问于 2018-06-12 09:10:37
回答 1查看 132关注 0票数 0

对于类别表,我使用cakephp-3树行为。这里的“sequence_no”字段用于对某个类别的子类别列表进行排序。我使用一个category_id搜索,以“sequence_no”按升序得到他所有的子类别。但命令不在这里工作。我的代码片段和输出在这里。

代码语言:javascript
复制
 $categoris = $this->Categories->find('children', ['for' => $id])
            ->find('threaded')
            ->contain('ParentCategories')
            ->order(['Categories.sequence_no' => 'ASC'])
            ->toArray();
  • 输出样本:
代码语言:javascript
复制
{
"status": "OK",
"result": {
    "data": [
        {
            "id": 15,
            "store_id": 0,
            "uuid": null,
            "name": "cat-3",
            "parent_id": 3,
            "lft": 16,
            "rght": 17,
            "sequence_no": 2,
            "url": "cat-3",
            "layout_id": 0,
            "status": 1,
            "total": 0,
            "created": "2018-06-12T07:36:15+00:00",
            "modified": "2018-06-12T08:15:12+00:00",
            "parent_category": {
                "id": 3,
                "store_id": 2,
                "uuid": null,
                "name": "Pants",
                "parent_id": null,
                "lft": 15,
                "rght": 20,
                "sequence_no": null,
                "url": "pants",
                "layout_id": 0,
                "status": 1,
                "total": 0,
                "created": "2018-06-06T10:23:50+00:00",
                "modified": "2018-06-06T10:23:50+00:00"
            },
            "children": []
        },
        {
            "id": 16,
            "store_id": 0,
            "uuid": null,
            "name": "cat-4",
            "parent_id": 3,
            "lft": 18,
            "rght": 19,
            "sequence_no": 1,
            "url": "cat-4",
            "layout_id": 0,
            "status": 1,
            "total": 0,
            "created": "2018-06-12T07:36:34+00:00",
            "modified": "2018-06-12T08:15:12+00:00",
            "parent_category": {
                "id": 3,
                "store_id": 2,
                "uuid": null,
                "name": "Pants",
                "parent_id": null,
                "lft": 15,
                "rght": 20,
                "sequence_no": null,
                "url": "pants",
                "layout_id": 0,
                "status": 1,
                "total": 0,
                "created": "2018-06-06T10:23:50+00:00",
                "modified": "2018-06-06T10:23:50+00:00"
            },
            "children": []
        }
    ]
}

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-12 13:54:17

由于findChildred查找器在查询中添加了一个ORDER lft asc子句,您的订单条件将被追加到该查询中。

如果你想强迫你的命令,你可以

代码语言:javascript
复制
->order(['Categories.sequence_no' => 'ASC'], true)

order()方法中的第二个参数告诉蛋糕覆盖之前的ORDER BY集。

请参阅手册,this段落的末尾

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50813367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档