我已经花了三天时间解决这个问题,但已经走到了死胡同,无法继续。我知道如何使用非 cakephp 方法获取所需的数据,但我更喜欢使用 cakephp 的模型关系。
我的模特
class User extends AppModel {
var $hasOne = 'Profile';
}
class Profile extends AppModel {
var $belongsTo = 'User';
var $hasAndBelongsToMany = array('Quad' => array('className' => 'Quad'));
}
class Quad extends AppModel{
var $belongsTo = 'User';
var $hasAndBelongsToMany = array ('Performer' => array ('className' =>'Performer'));
}
class Performer extends AppModel {
var $name = 'Performer';
var $hasAndBelongsToMany = array('Quad' => array('className' => 'Quad'));
}
我的 HABTM 表
(perfomers:id|name|image|created|modified) (quads:id|user_id|etc.....) (performers_quads:id|performer_id|quad_id)
MY Profiles Controller 索引方法
public function index($uid) {
$user = $this->Profile->User->find('all', array(
'contain' => array(
'Quad' => array('contain'=>array('Performer'))),
'conditions' => array(
'User.id' => $uid)));
$this->set(compact('user'));
}
我的结果数组
UserArray (
[0] => Array (
[User] => Array (
[id] => 19
[email] => *****@gmail.com
[password] => ***
[created] => 2013-06-13 23:35:42
[modified] => 2013-06-13 23:35:42 )
[Profile] => Array (
[id] => 21
[user_id] => 19
[username] => ****
[first_name] => ****
[last_name] => ****
[imageId] => ****.jpg
[created] => 2013-06-13 23:35:43
[modified] => 2013-06-17 01:05:22 )
[Quads] => Array (
[0] => Array (
[id] => 65 [user_id] => 19
[title] => Test Event
[date] => 2013-06-15 16:53:00
[price] => 25.00
[venueID] => 1
[created] => 2013-06-17 01:05:22 )
[1] => Array (
[id] => 66
[user_id] => 19
[title] => Test Event 2
[date] => 2013-06-12 17:12:00
[price] => 50.00
[venueID] => 1
[created] => 2013-06-17 01:05:22 ) ) ) )
我需要的
UserArray (
[0] => Array (
[User] => Array (
[id] => 19
[email] => *****@gmail.com
[password] => ***
[created] => 2013-06-13 23:35:42
[modified] => 2013-06-13 23:35:42 )
[Profile] => Array (
[id] => 21
[user_id] => 19
[username] => ****
[first_name] => ****
[last_name] => ****
[imageId] => ****.jpg
[created] => 2013-06-13 23:35:43
[modified] => 2013-06-17 01:05:22 )
[Quads] => Array (
[0] => Array (
[id] => 65 [user_id] => 19
[title] => Test Event
[date] => 2013-06-15 16:53:00
[price] => 25.00
[venueID] => 1
[created] => 2013-06-17 01:05:22
[Performer] => Array(
[0] => Array(
[id] => ***
[name] => ****
etc....)))
[1] => Array (
[id] => 66
[user_id] => 19
[title] => Test Event 2
[date] => 2013-06-12 17:12:00
[price] => 50.00
[venueID] => 1
[created] => 2013-06-17 01:05:22
[Performer] => Array(
[0] => Array(
[id] => ***
[name] => ****
etc....)))))))
我想要完成的是在 ProfilesController 中获取属于用户的 Quads 的执行者。对此的任何帮助将不胜感激。