蛋糕php 2订单模型查询结果按阵列顺序
我正在蛋糕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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论