蛋糕php 2订单模型查询结果按阵列顺序

发布于 2025-01-22 18:53:33 字数 864 浏览 3 评论 0原文

我正在蛋糕2项目中做一些开发人员工作。我有一个称为queuemanagerjob的模型和一个称为queue的列,我需要能够按阵列的顺序订购在此模型上检索的数据(转换为转换)通过一个逗号分隔的列表),我最初认为蛋糕在给出数组时能够处理它,但似乎不是吗?

我有一个持有一个名为$ queue的变量,该阵列看起来像:

array(3) {
  [0]=>
  string(3) "now"
  [1]=>
  string(5) "later"
  [2]=>
  string(7) "default"
}

我的模型查询是:

$jobs = $this->QueueManagerJob->find('all', array(
    'conditions' => array(
        'QueueManagerJob.reserved_at' => null,
        'QueueManagerJob.queue' => $queue
    ),
    'order' => array(
        'QueueManagerJob.available_at' => 'desc'
    ),
    'limit' => $limit
));

我可以,从理论上讲,我可以执行三个查询,我可以循环循环$ queue array由于foreach会按顺序进行,并在每个查询中进行查询,然后在以后的日期合并,但是我认为这将是非常效率的,因为会有一个未知数的队列。

I'm doing some dev work in a Cake PHP 2 project. I have a model called QueueManagerJob and a column called queue, I need to be able to order the data retrieved on this model by the order of an array (converted by a comma separated list), I initially thought that Cake would be able to handle this when given an array, but it doesn't seem to be?

I have a variable holding an array called $queue which looks like:

array(3) {
  [0]=>
  string(3) "now"
  [1]=>
  string(5) "later"
  [2]=>
  string(7) "default"
}

My model query is:

$jobs = $this->QueueManagerJob->find('all', array(
    'conditions' => array(
        'QueueManagerJob.reserved_at' => null,
        'QueueManagerJob.queue' => $queue
    ),
    'order' => array(
        'QueueManagerJob.available_at' => 'desc'
    ),
    'limit' => $limit
));

I could, in theory perform three queries, I could loop over my $queue array since a foreach would be in order, and perform a query in each one and then merge at a later date but this would be quite inefficient I think as there's going to be an unknown number of queues.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文