我被困在使用可包含行为的 CakePhp 查询中。所以我有 - 模型订单 HABTM 产品
我想接受特定州的订单以及在特定餐厅至少有一种产品的订单。
为了让您更好地理解,这看起来像架构
(int) 110 => array(
'Order' => array(
'id' => '10',
'customer_id' => '3',
'state_id' => '6',
'payment_id' => '3',
'created' => '2012-11-10 12:23:03',
'user_id' => '10',
'date_delivery' => '2012-10-12 20:30:00',
'km' => '2.76'
),
'Product' => array(
(int) 0 => array(
'id' => '51',
'category_id' => '2',
'restaurant_id' => '10001',
'title' => 'aaa',
'description' => 'aaa',
'price' => '8.2',
'tva_id' => '2',
'img' => 'aaa',
'maj_img' => '2012-10-24 15:38:56',
'ProductsOrder' => array(
'id' => '57',
'product_id' => '51',
'order_id' => '10',
'quantity' => '1',
'price' => '8.2',
'tva_id' => '2',
'meal' => null
)
)))
(ProductsOrder 是连接表)
所以,我正在使用可包含的行为,这是我的查询:
$q = $this->Order->find('all', array(
'conditions' => array(
'Order.date_delivery BETWEEN ? AND ?' => array($dateDebut->format('Y-m-d H:i:s'), $dateFin->format('Y-m-d H:i:s')),
'Order.state_id' => array(6, 8)),
'order' => 'Order.date_delivery',
'contain' => array(
'Product' => array(
'conditions' => array('Product.restaurant_id' => $id),
)
)
));
问题是查询的结果返回了一些我不想要的条目。这是一个示例,它是结果查询的一部分,并且假设不存在。 请注意,Product 是一个空数组。
109 => array(
'Order' => array(
'id' => '179',
'customer_id' => '139',
'state_id' => '6',
'payment_id' => '3',
'created' => '2012-11-18 22:29:16',
'user_id' => '10',
'date_delivery' => '2012-10-12 20:00:00',
'coursier_id' => '19',
'comment' => '',
'km' => '10.7'
),
'Product' => array()
如果您知道如何解决这个问题,您可以救我...谢谢
编辑转储 SQL
count从中选择计数(*)live_resto_manager。在restaurants哪里。= 10001RestaurantRestaurantid
选择Order。id, Order. customer_id, Order. state_id, Order. payment_id, Order. created, Order. user_id, Order. date_delivery, Order. coursier_id, Order. comment, Order. km从live_resto_manager。在orders哪里。在 '2012-10-01 00:00:00' 和 '2012-10-31 23:59:00' 和 之间。在 (6, 8) 中排序。ASCOrderOrderdate_deliveryOrderstate_idOrderdate_delivery
选择Product。id, Product. category_id, Product. restaurant_id, Product. title, Product. description, Product. price, Product. tva_id, Product. img, Product. maj_img, ProductsOrder. id, ProductsOrder. product_id, ProductsOrder. order_id, ProductsOrder. quantity, ProductsOrder. price, ProductsOrder. tva_id, ProductsOrder. meal从live_resto_manager。products作为Product加入live_resto_manager。products_orders如ProductsOrder开 ( ProductsOrder.order_idIN (99, 100, 102, 105, 101, 103, 104, 1, 58, 3, 106, 108, 2, 31, 107, 109, 110, 111, 59, 112, 114, 115, 117, 118, 61, 113, 33, 116, 60, 119, 120, 121, 122, 4, 62, 34, 123, 63, 124, 125, 5, 6, 126, 129, 127, 128, 130, 131, 133, 132, 134, 135, 138, 137, 139, 140, 141, 64, 136, 142, 143, 35, 36, 37, 144, 145, 146, 147, 149, 148, 150, 151, 152, 153, 7, 154, 155, 65, 156, 158, 159, 161, 8, 157, 162, 160, 163, 9, 165, 166, 66, 164, 168, 38, 167, 169, 39, 170, 171, 172, 173, 67, 174, 175, 68, 69, 176, 177, 178, 179, 10, 40, 180, 181, 182, 192, 183, 184, 186, 187, 70, 185, 189, 190, 12, 188, 191, 193, 13, 14, 41, 194, 11, 195, 15, 71, 196, 197, 200, 201, 72, 198, 199, 202, 16, 73, 203, 42, 204, 205、74、206、207、208、209、43、210、212、44、211、45、17、76、213、214、215、75、77、216、78、217、218、219、79、 220、221、222、223、80、224、46、225、81、18、229、233、226、227、228、230、231、232、234、47、236、235、237、238、239、19、242、243、244、48、49、50、240、241、245、 20, 51, 246, 247, 248, 250, 251, 253, 254, 256, 257, 258, 260, 262, 252, 255, 82, 249, 259, 261, 263, 265, 264, 266, 267, 83, 84, 269, 85, 268, 270, 271, 86, 272, 21, 87, 274, 273, 275, 90, 276, 277, 88, 89, 278, 279, 280, 281, 282, 284, 285、287、288、283、91、22、286、289、290、294、298、24、291、292、295、296、297、25、52、92、93、23、299、300、301、 302, 53, 32, 303, 304, 305, 306, 309, 307, 308, 54, 94, 293, 55, 310, 312, 311, 313, 314, 316, 315, 317, 318, 319, 95, 320, 321, 96, 56, 26, 322, 325, 323, 324, 326, 328, 329, 330, 327, 97, 27, 28, 29, 30, 98, 331, 333, 332, 334, 335, 57、336、337、338)和246、247、248、250、251、253、254、256、257、258、260、262、252、255、82、249、259、261、263、265、264、266、267、83、84、 269、85、268、270、271、86、272、21、87、274、273、275、90、276、277、88、89、278、279、280、281、282、284、285、287、 288、283、91、22、286、289、290、294、298、24、291、292、295、296、297、25、52、92、93、23、299、300、301、302、53、 32, 303, 304, 305, 306, 309, 307, 308, 54, 94, 293, 55, 310, 312, 311, 313, 314, 316, 315, 317, 318, 319, 95, 320, 321, 96, 56, 26, 322, 325, 323, 324, 326, 328, 329, 330, 327, 97, 27, 28, 29, 30, 98, 331, 333, 332, 334, 335, 57, 336, 337, 338) 和246、247、248、250、251、253、254、256、257、258、260、262、252、255、82、249、259、261、263、265、264、266、267、83、84、 269、85、268、270、271、86、272、21、87、274、273、275、90、276、277、88、89、278、279、280、281、282、284、285、287、 288、283、91、22、286、289、290、294、298、24、291、292、295、296、297、25、52、92、93、23、299、300、301、302、53、 32, 303, 304, 305, 306, 309, 307, 308, 54, 94, 293, 55, 310, 312, 311, 313, 314, 316, 315, 317, 318, 319, 95, 320, 321, 96, 56, 26, 322, 325, 323, 324, 326, 328, 329, 330, 327, 97, 27, 28, 29, 30, 98, 331, 333, 332, 334, 335, 57, 336, 337, 338) 和22、286、289、290、294、298、24、291、292、295、296、297、25、52、92、93、23、299、300、301、302、53、32、303、304、 305, 306, 309, 307, 308, 54, 94, 293, 55, 310, 312, 311, 313, 314, 316, 315, 317, 318, 319, 95, 320, 321, 96, 56, 26, 322, 325, 323, 324, 326, 328, 329, 330, 327, 97, 27, 28, 29, 30, 98, 331, 333, 332, 334, 335, 57, 336, 337, 338) 和22、286、289、290、294、298、24、291、292、295、296、297、25、52、92、93、23、299、300、301、302、53、32、303、304、 305, 306, 309, 307, 308, 54, 94, 293, 55, 310, 312, 311, 313, 314, 316, 315, 317, 318, 319, 95, 320, 321, 96, 56, 26, 322, 325, 323, 324, 326, 328, 329, 330, 327, 97, 27, 28, 29, 30, 98, 331, 333, 332, 334, 335, 57, 336, 337, 338) 和ProductsOrder. product_id= Product。id) 在哪里Product。restaurant_id= 10001
哇哦,这太丑了