cakephp saveAssociated只能部分工作

时间:2016-09-22 19:21:10

标签: php cakephp-2.0

我正在开发我的应用程序在cakephp 2.3.0中,我在这里看了很多帖子并检查了cakephp书,据我所知,两个数组都设置正确,但是当它保存时它只保存第一个数组[' TaskSchedulerPendingEmailBatch']任何帮助都将不胜感激。

模型

TaskSchedulerPendingEmail

entervar $belongsTo = array(
    'TaskSchedulerPendingEmailBatch' => array(
        'className' => 'TaskScheduler.TaskSchedulerPendingEmailBatch',
        'foreignKey' => 'task_scheduler_email_batch_id',
        'counterCache' => 'pending_count',
        'counterScope' => array(
            'TaskSchedulerPendingEmail.completed' => null,
        )
    )
);

var $hasMany = array(
    'TaskSchedulerEmailAttachment' => array(
        'className' => 'TaskScheduler.TaskSchedulerEmailAttachment',
        'foreignKey' => 'task_scheduler_email_id',
        'dependent' => true,
        'exclusive' => true
    )
); 

TaskSchedulerPendingEmailBatch

var $belongsTo = array(
    'TaskSchedulerTask' => array(
        'className' => 'TaskScheduler.TaskSchedulerTask',
        'allowEmpty' => true
    )
);

var $hasMany = array(
    'TaskSchedulerPendingEmail' => array(
        'className' => 'TaskScheduler.TaskSchedulerPendingEmail',
        'foreignKey' => 'task_scheduler_email_batch_id',
        'dependent' => true,
        'exclusive' => true
    )
);

Shell任务代码

 $dataALL['TaskSchedulerPendingEmailBatch']['task_scheduler_task_id'] = $ts_mailout_info[0]['TaskSchedulerMailout']['task_scheduler_task_id'];
        $dataALL['TaskSchedulerPendingEmailBatch']['name'] = $ts_class_name[0]['TaskSchedulerClass']['name'].' from "'.$ts_mailout_info[0]['TaskSchedulerMailout']['name'].'"';
        $dataALL['TaskSchedulerPendingEmailBatch']['pending_count'] = 1;
        $dataALL['TaskSchedulerPendingEmailBatch']['sent_count'] = 0;
        $dataALL['TaskSchedulerPendingEmailBatch']['attempt_count'] = 0;
        $dataALL['TaskSchedulerPendingEmailBatch']['error'] = 0;

       $dataALL['TaskSchedulerPendingEmail'][0]['task_scheduler_task_id'] = '1';
       $dataALL['TaskSchedulerPendingEmail'][0]['created'] = getdate();
       $dataALL['TaskSchedulerPendingEmail'][0]['template'] = $ts_mailout_info[0]['TaskSchedulerMailout']['template'];
       $dataALL['TaskSchedulerPendingEmail'][0]['email_format'] = $ts_mailout_info[0]['TaskSchedulerMailout']['email_format'];
       $dataALL['TaskSchedulerPendingEmail'][0]['to'] = $pdf_form['User']['email'];
       $dataALL['TaskSchedulerPendingEmail'][0]['from'] = $ts_mailout_info[0]['TaskSchedulerMailout']['from'];
       $dataALL['TaskSchedulerPendingEmail'][0]['subject'] = $ts_mailout_info[0]['TaskSchedulerMailout']['subject'];
       $dataALL['TaskSchedulerPendingEmail'][0]['title_for_layout'] = $ts_mailout_info[0]['TaskSchedulerMailout']['title_for_layout'];
       $dataALL['TaskSchedulerPendingEmail'][0]['message'] = '<p>job id: ' . $pdf_form['Job']['id'] . '</p> <p>descrption: ' . $pdf_form['Job']['description'] . '</p> <p>status: ' . $pdf_form['Job']['status_id'] . '</p>';
       $dataALL['TaskSchedulerPendingEmail'][0]['error'] = '0';




  $this->TaskSchedulerPendingEmailBatch = ClassRegistry::init('TaskSchedulerPendingEmailBatch');
  $this->TaskSchedulerPendingEmailBatch->saveAssociated($dataALL);

1 个答案:

答案 0 :(得分:0)

您尝试保存的数组结构是Google Places API Web Service关系,但您使用模型hasMany保存数组,TaskSchedulerPendingEmail belongsTo

尝试使用

保存
TaskSchedulerPendingEmailBatch

而不是

$this->TaskSchedulerPendingEmailBatch->saveAssociated($dataALL);

您可以退出 $this->TaskSchedulerPendingEmail->saveAssociated($dataALL, array('deep' => true)); ,因为您没有保存嵌套模型。