0
相關模型的檢索,我檢索數據隨機順序:CakePHP的模型關聯 - 對HABTM
$mydata = $this->ProductList->find('all', array('order' => 'rand()', 'conditions' => array('name' => 'we love')));
我已經設置了產品模型HABTM關係。正如您所看到的,我正在獲取'我們愛'列表中的所有產品。現在,我希望我檢索的那些產品是隨機的。但它們不是,而是像SQL中所看到的那樣,MySQL在ProductList模型上隨機化。這是爲什麼?我如何才能在產品上進行隨機獲取?
得到的MySQL查詢:
SELECT `ProductList`.`id`, `ProductList`.`name` FROM `database`.`product_lists` AS `ProductList` WHERE `name` = 'we love' ORDER BY rand() ASC
SELECT `Product`.`id`, `Product`.`category_id`, `Product`.`name`, `Product`.`price`, `Product`.`description`, `ProductListsProduct`.`product_list_id`, `ProductListsProduct`.`product_id` FROM `database`.`products` AS `Product` JOIN `database`.`product_lists_products` AS `ProductListsProduct` ON (`ProductListsProduct`.`product_list_id` = 3 AND `ProductListsProduct`.`product_id` = `Product`.`id`)
好的,但是複製我以前的病狀的語法是什麼?你的'...'是重要的一點,但是被省略了。 – alieninlondon