【发布时间】:2014-08-04 17:45:11
【问题描述】:
在这里阅读 Cookbook 和其他 SO 帖子后,我有点困惑..
我有以下3级关系:
Project (has customer_id) -> Customer (has user_id) -> User
我希望能够将 用户 条件传递到我的项目分页函数中。我怎样才能做到这一点?我认为我必须正确连接我目前没有做的三个模型......
ProjectsController 看起来像:
$this->paginate = array(
'contain' => array('Customer' => array('User')),
'order' => 'Project.id ASC',
'conditions' => $condition,
'limit' => $limit
);
项目模型有:
public $belongsTo = 'Customer';
客户模型有:
public $belongsTo = 'User';
public $hasMany = array('Order', 'Project');
用户模型有:
public $hasOne = array(
'Customer' => array(
'className' => 'Customer',
'conditions' => array('User.role' => 'Customer'),
'dependent' => false
)
【问题讨论】:
-
I want to pull out the User data into the parent "level":- 很容易做到,但是:为什么? -
它可以让我更轻松地使用 Paginate 功能。我正在尝试对用户数据的项目视图进行分页。
-
所以你想跨 3 个表加入 - 你为什么不问怎么做,而不是听起来像表面上的改变?
-
是的,你是对的,我不知道我为什么要这样陷害它。我会改写它!
标签: cakephp model pagination associations