dtkmejg127475 2010-09-13 16:22
浏览 64

Cakephp返回空,但sql查询有结果

I have been fighting with this code:

function getNextActionFObyBalance($when) {

  $theQuery = $this->find('first', array(
   'fields' => array(
     'Contract.id',
     'Contract.start_balance'
    ),
    'conditions' => array(
    'AND' => array(
      'Status.next_action_by' => 'frontoffice',
      'Status.status_type' => 'active',
      'Status.visibility' => 'frontoffice',
      'OR' => array(
        'Contract.next_action_on' => null,
    'Contract.next_action_on <=' => $when
      )
    )),
    'order' => 'Contract.start_balance DESC',
    'recursive' => 0,
  ));
  return $theQuery;
}

I have enabled logging on the MySQL server at this is what the server indicates that CakePHP is requesting:

SELECT `Contract`.`id`, `Contract`.`start_balance` FROM `contracts` AS `Contract` LEFT JOIN `statuses` AS `Status` ON (`Contract`.`status_id` = `Status`.`id`) LEFT JOIN `users` AS `User` ON (`Contract`.`user_id` = `User`.`id`)  WHERE ((`Status`.`next_action_by` = 'frontoffice') AND (`Status`.`status_type` = 'active') AND (`Status`.`visibility` = 'frontoffice') AND (((`Contract`.`next_action_on` IS NULL) OR (`Contract`.`next_action_on` <= '2010-09-13 10:13:04'))))   ORDER BY `Contract`.`start_balance` DESC  LIMIT 1

if I use that in the phpmyadmin tool, I get exactly what I was expecting 1 record with two fields. BUT CakePHP just gives me an empty result set. Can anyone enlighten me?

PS the code was working but I can figure out what changed!

  • 写回答

2条回答 默认 最新

  • doure5236 2010-09-13 16:44
    关注

    Presumably this method is defined in models/contract.php?

    The recursive = 0 statement looks a bit suspect to me. Are the models correctly related in their respective model files?

    Have you tried loadModel in case the associations aren't working properly?

    It would be useful to see the relationship definitions from the respective models.

    --EDIT-- I've formatted the code from your comment here as I can't edit your OP

    var $belongsTo = array(
        'Status' => array( 
            'className' => 'Status', 
            'foreignKey' => 'status_id', 
                         ), 
        'User' => array( 
            'className' => 'User', 
            'foreignKey' => 'user_id', 
                         )
                     ); 
    
    var $hasMany = array( 
        'Transaction' => array( 
            'className' => 'Transaction', 
            'foreignKey' => 'contract_id', 
            'dependent' => false, 
                          )
                     );
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致