So I'm linking two of my models together and it's returning something like:
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
)
)
)
Sometimes, however, the number of votes will be from [0] - [n]. This is for my $newestSubmissions
. The query I'm doing to give me that is:
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'
));
}
What I'd like to do is to retrieve all votes throughout the $newestSubmissions
array object as well as all of the votes (query below) on each of the $newestSubmissions
to calculate the actual score so I can send a single array object called $newestSubmissions
to my view, instead of $newestSubmissions
and $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'];
}
Basically I want to send a single score to my view along with all the other information in the array object instead of having to send an inner indexed array object within my parent array object (which is what I'm currently getting).
How can I do this?