【发布时间】:2012-02-28 20:01:58
【问题描述】:
关于 cakePHP 查找操作中的 orderBy 的一个简单问题。假设我有 3 个相互关联的模型。当我对我的 3 个模型中的任何一个进行 find('all') cakePHP 查询时,我得到的结果还包括来自其他 2 个模型的数据。例如,假设我的模型是:
1- User
2- School
3- Country
如果我在UsersController 里面做$this->find('all'),因为我的三个模型链接在一起,我会得到这样的结果:
Array
(
[0] => Array
(
[User] => Array
(
[id] => 'the_auto_incrementing_id'
// other table columns
[created] 'creation_date'
[modified] 'modification_date'
)
[School] => Array
(
[id] => 'the_auto_incrementing_id'
// other table columns
[created] 'creation_date'
[modified] 'modification_date'
)
[Country] => Array
(
[id] => 'the_auto_incrementing_id'
// other table columns
[created] 'creation_date'
[modified] 'modification_date'
)
)
)
我的问题是,虽然我的 find('all') 查询是在 User 模型上发起的,但是否可以 orderBy 比如说模型 School 中的 created 字段?
如果可以的话,请告诉我
谢谢
【问题讨论】:
标签: php cakephp cakephp-1.3 sql-order-by model-associations