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 9164769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:45:38+00:00 2026-06-17T14:45:38+00:00

The following query returns an array containing the proper ids, but null for all

  • 0

The following query returns an array containing the proper ids, but null for all values.

If I remove the aggregation function (AVG()), it returns values (not the averaged ones of course), if I choose e.g. find('all') it returns the average, but not in the list format I want (I could work with that, but I want to try to do it with 'list' first).

$progress = $this->Trial->find('list', array(
    'fields' => array(
        'Trial.session_id',
        'AVG(Trial.first_reaction_time_since_probe_shown) AS average_reaction_time'
    ),
    'group' => 'Trial.session_id',
    'conditions' => array(
        'Trial.first_valid_response = Trial.probe_on_top',
        'TrainingSession.user_id IS NOT NULL'
    ),
    'contain' => array(
        'TrainingSession' => array(
            'conditions' => array(
                'TrainingSession.user_id' => $this->Auth->user('id') 
            )
        )
    ),
    'recursive' => 1,
));

The generated SQL query returns exactly the result I want, when I send it to the DB via PhpMyAdmin.

SELECT 
    `Trial`.`session_id`, 
    AVG(`Trial`.`first_reaction_time_since_probe_shown`) AS average_reaction_time 
FROM 
    `zwang`.`trials` AS `Trial` 
LEFT JOIN 
    `zwang`.`training_sessions` AS `TrainingSession` ON (
        `Trial`.`session_id` = `TrainingSession`.`id` AND
        `TrainingSession`.`user_id` = 1
    )
WHERE 
    `Trial`.`first_valid_response` = `Trial`.`probe_on_top` 
GROUP BY 
    `Trial`.`session_id`

I’ve examined the source for find(‘list’). I think it’s due to the “array path” for accessing the list getting screwed up when using functions in the query, but I couldn’t fix it yet (or recognise my abuse of CakePHP logic).

  • 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-17T14:45:39+00:00Added an answer on June 17, 2026 at 2:45 pm

    Once I posted the question, Stackoverflow started relating the correct answers to me.

    Apparently, it can’t be done with 'list' without virtualFields.
    I didn’t expect that because it worked using the other find-types.

    $this->Trial->virtualFields = array(
        'average_reaction_time' => 'AVG(Trial.first_reaction_time_since_probe_shown)'
    );
    $progress = $this->Trial->find('list', array(
        'fields' => array('Trial.session_id','average_reaction_time')
        /* etc... */ 
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following query returns values for months with sales but not for months where
I have the following query, which returns a single row. MODEL: function get_guide_first(){ $this->db
I have an array, $scans. I want to query MySQL with all the values
Basic php question here. The following SQL code returns an array containing a key
The following query returns the total amount of orders, per week, for the past
I have the following query which returns a list of questions and the possible
The prepared query returns the following resultset, when $this->show is set to saved-by-the-bell :
I have the following MQL query which successfully returns the record for William Shakespeare.
I am running the following query and checking whether it returns any results and
I would like to create a query that returns rows in the following format:

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.