2013-03-09 5 views
0

SaveAll не работает, может кто-нибудь помочь мне найти, в чем проблема. Я включил действие контроллера, массив передал saveAll и его модель.cakephp: saveAll не работает

Действие контроллеры, содержащий SaveAll выглядит включено следующее:

public function add_customer_order() { 
    if ($this->request->is('post')) { 
         - 
         - 
         - 
         - 
        $this->CustomerOrderItem->create(); 
        if ($this->CustomerOrderItem->saveAll($customer_order_item)) { 
         $this->Session->setFlash('The customer order Items has been saved successfully.', 'default/flash_success'); 
        } 
       else { 
        $this->Session->setFlash('The customer order Items not been saved successfully.', 'default/flash_success'); 
       } 
    } 

} 

массив $ customer_order_item выглядит следующим образом-

array(
    'CustomerOrderItem' => array(
     (int) 0 => array(
      'id' => '', 
      'quantity' => '400', 
      'unit_cost' => '77', 
      'pending_quantity' => '400', 
      'packaging_configuration_quantity' => '20', 
      'exercise_duty_id' => '0', 
      'tax_id' => '5', 
      'customer_order_id' => '', 
      'master_article_id' => '22' 
     ), 
     (int) 1 => array(
      'id' => '', 
      'quantity' => '200', 
      'unit_cost' => '77', 
      'pending_quantity' => '200', 
      'packaging_configuration_quantity' => '20', 
      'exercise_duty_id' => '0', 
      'tax_id' => '5', 
      'customer_order_id' => '', 
      'master_article_id' => '25' 
     ), 
     (int) 2 => array(
      'id' => '', 
      'quantity' => '400', 
      'unit_cost' => '77', 
      'pending_quantity' => '400', 
      'packaging_configuration_quantity' => '20', 
      'exercise_duty_id' => '1', 
      'tax_id' => '5', 
      'customer_order_id' => '', 
      'master_article_id' => '23' 
     ), 
     (int) 3 => array(
      'id' => '', 
      'quantity' => '200', 
      'unit_cost' => '77', 
      'pending_quantity' => '200', 
      'packaging_configuration_quantity' => '20', 
      'exercise_duty_id' => '1', 
      'tax_id' => '5', 
      'customer_order_id' => '', 
      'master_article_id' => '24' 
     ), 
     (int) 4 => array(
      'id' => '', 
      'quantity' => '200', 
      'unit_cost' => '77', 
      'pending_quantity' => '200', 
      'packaging_configuration_quantity' => '20', 
      'exercise_duty_id' => '1', 
      'tax_id' => '5', 
      'customer_order_id' => '', 
      'master_article_id' => '27' 
     ) 
    ) 
) 

модель выглядит следующим образом-

<?php 
App::uses('AppModel', 'Model'); 
/** 
* CustomerOrderItem Model 
* 
* @property CustomerOrder $CustomerOrder 
* @property MasterArticle $MasterArticle 
*/ 
class CustomerOrderItem extends AppModel { 

/** 
* Validation rules 
* 
* @var array 
*/ 
    public $validate = array(
     'customer_order_id' => array(
      'numeric' => array(
       'rule' => array('numeric'), 
       //'message' => 'Your custom message here', 
       //'allowEmpty' => false, 
       //'required' => false, 
       //'last' => false, // Stop validation after this rule 
       //'on' => 'create', // Limit validation to 'create' or 'update' operations 
      ), 
     ), 
     'master_article_id' => array(
      'numeric' => array(
       'rule' => array('numeric'), 
       //'message' => 'Your custom message here', 
       //'allowEmpty' => false, 
       //'required' => false, 
       //'last' => false, // Stop validation after this rule 
       //'on' => 'create', // Limit validation to 'create' or 'update' operations 
      ), 
     ), 
    ); 

    //The Associations below have been created with all possible keys, those that are not needed can be removed 

/** 
* belongsTo associations 
* 
* @var array 
*/ 
    public $belongsTo = array(
     'CustomerOrder' => array(
      'className' => 'CustomerOrder', 
      'foreignKey' => 'customer_order_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ), 
     'MasterArticle' => array(
      'className' => 'MasterArticle', 
      'foreignKey' => 'master_article_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 
} 
+0

как не работает? любое сообщение? –

+0

как насчет значения customer_order_id в вашем массиве ..? почему это NULL? – kumar

ответ

0

Попробуйте

if ($this->CustomerOrderItem->saveAll($this->request->data)) { 
+0

Массив, который я опубликовал, является форматированным массивом, который вырван из $ this-> request-> data –

1

Я уверен, что это проблема с данными из-за проверки или null в db.

  1. отлаживать содержание debug($this->request->data);
  2. отладки недопустимые поля, если любой debug($this->Submission->invalidFields());. Убедитесь, что вы называете это после того, как у вас есть вопросы validates() запроса или saveAll()
+0

Отличный !! Отладка решила мою проблему. большое спасибо –

0

Прежде всего удалить все правила проверки, а затем проверить еще раз, если ошибка все еще не coming.if то должна быть проблемой с правилами проверок данных или нулем значение «customer_order_id».

Смежные вопросы