的计数的搜索,我需要做一个搜索,通过相关的表中的“计数”的过滤,但我不能这样做..CakePHP的由相关表
下面是该查询:
$this->paginate = array
(
'Establishment' => array
(
'conditions' => array
(
'EstablishmentsCategory.slug' => $category,
),
'limit' => 10,
'order' => $order,
'fields' => array('Establishment.*'),
'contain' => array
(
'EstablishmentsCategory',
'EstablishmentsImage',
'EstablishmentsCoupon' => array('fields' => array('id'))
)
)
);
$data = $this->paginate('Establishment');
现在这个返回的数组是这样的:
[0] => Array
(
[Establishment] => Array
(
[id] => 2
[establishments_category_id] => 1
[slug] => xxxxxx
[name] => xxxxxx
[description] => xxxxxx
[active] => 0
[modified] => 2012-01-25 15:31:23
[created] => 2011-07-29 10:03:51
)
[EstablishmentsCategory] => Array
(
[id] => 1
)
[EstablishmentsCoupon] => Array
(
[0] => Array
(
[id] => 2
[establishment_id] => 2
)
)
[EstablishmentsImage] => Array
(
[0] => Array
(
[id] => 2
[establishment_id] => 2
[image] => fsdfsdf.jpg
[created] => 2012-01-10 11:34:06
)
[1] => Array
(
[id] => 3
[establishment_id] => 2
[image] => werwerwer.jpg
[created] => 2012-01-10 11:34:06
)
[2] => Array
(
[id] => 4
[establishment_id] => 2
[image] => werwerwer.jpg
[created] => 2012-01-10 11:34:06
)
[3] => Array
(
[id] => 7
[establishment_id] => 2
[image] => werwerer2.jpg
[created] => 2012-01-10 13:31:01
)
)
)
问题:我需要找到,所有的“立”,thah有一个或多个“EstablishmentsCoupon”。我找不到解决方案:S
有什么不对你的归来?使用'contains'语句时,您使用内部联接进行查询,因此只返回具有EstablishmentsCoupon的企业。 – 2012-03-01 12:53:36
其实,数组返回与EstablishmentsCoupon和没有EstablishmentsCoupon创建,我只需要建立有一个或多个EstablishmentsCoupon。 在这种情况下,我有一个EstablishmentsCoupon,但如果创建没有任何EstablishmentsCoupon(空数组),我需要删除它。 – Zenth 2012-03-01 16:56:52