从两个连接表中检索所有投票

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?

OK... I tried to post this just as a comment, but it was too long. It's not really an answer as such.

Do you know about the containable behaviour? Check it out - it's good for determining what data you get back: http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html

Also, if you were to break your submissions vote table into two tables - upvotes and downvotes, then you could also use Cake's counterCache behaviour to keep track of the number of up/down votes directly in your 'submissions' table (you'd need to add upvote_count and downvote_count columns to your submissions table to do so).

This would make calculating submission score easier - and you wouldn't have to fetch all votes from the database to do it each time. For doco, search for counterCache on this page: http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html It could be worth considering.

  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',
                    'submissionsvotes.vote_type'
                ),
                'joins' => array(
                            array(
                            'table' => 'SubmissionsVote',
                            'alias' => 'submissionsvotes',
                            'type' => 'LEFT', 
                            'conditions' => array
                            ('User.id = SubmissionsVotes.user_id','Submission.id'=>'SubmissionsVotes.submission_id')
                            ),
                        )


               'group'=>'submissionsvotes.vote_type',
               'order' => 'Submission.created DESC'
            )
    );