所以我将我的两个模型链接在一起,它返回的内容如下:
Array
(
[Submission] => Array
(
[id] => 47
[user_id] => 0
[title] => asdfasdfsa dfasdf asdfa sfa fadf
[source] => http://www.aol.com
[slug] =>
[category] => health
[created] => 2012-06-25 11:30:16
)
[User] => Array
(
[id] => 2
[username] => john
)
[SubmissionsVote] => Array
(
[0] => Array
(
[id] => 247
[user_id] => 2
[submission_id] => 47
[vote_type] => up
)
)
)
但是,有时投票数会在 [0] - [n] 之间。这是给我的$newestSubmissions
。我正在做的查询是:
public function newestSubmissions() {
$this->unBindModel(
array('hasMany' => array('Comment')));
return $this->find('all', array(
'fields' => array(
'Submission.id',
'Submission.user_id',
'Submission.title',
'Submission.source',
'Submission.slug',
'Submission.category',
'Submission.created',
'User.id',
'User.username'
),
'order' => 'Submission.created DESC'
));
}
我想要做的是检索整个$newestSubmissions
数组对象的所有投票以及每个投票的所有投票(下面的查询)$newestSubmissions
以计算实际分数,这样我就可以将调用的单个数组对象发送$newestSubmissions
到我的视图,而不是的$newestSubmissions
和$submissionScore
public function getVoteType($userId, $submissionId) {
$voteType = $this->find('all', array(
'conditions' => array(
'User.id' => $userId,
'Submission.id' => $submissionId),
'fields' => array(
'SubmissionsVote.vote_type'),
'limit' => '1'
));
return $voteType[0]['SubmissionsVote']['vote_type'];
}
基本上我想将一个分数连同数组对象中的所有其他信息一起发送到我的视图,而不是必须在我的父数组对象中发送一个内部索引数组对象(这是我目前得到的)。
我怎样才能做到这一点?