我有一个如上所述的用例。在我的CategoriesController.php
中,我进行Category
如下查询:
$category = $this->Category->Transaction->find("first", array(
"fields" => array("Category.*", "COUNT(*) AS TOTAL", "AVG(Transaction.debit) AS AVERAGE_COST"),
"conditions" => array("not" => array("Transaction.debit" => null)),
"contain" => array("Category" => array("CategoryType")),
"group" => "Transaction.category_id",
"order" => array("TOTAL" => "desc"),
));
这就是我得到的回报:
Array
(
[Category] => Array
(
[id] => 2
[name] => FOOD
[category_type_id] => 2
)
[0] => Array
(
[TOTAL] => 4596
[AVERAGE_COST] => 7.668451
)
)
问题:如何CategoryType
在返回字段中指定?
我尝试过Category.CategoryType.*
并且CategoryType.*
没有工作。但是如果我完全取出fields
数组,让cakephp默认处理,cakephp设法返回数组中的CategoryType。