Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:22:52+00:00 2026-06-09T17:22:52+00:00

So I’m linking two of my models together and it’s returning something like: Array

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:22:53+00:00Added an answer on June 9, 2026 at 5:22 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.