Wednesday, July 18, 2012

saveAssociated Help

Hi people.. I have a trouble on the saveAssociated method, please if some onw could give me a help, my problem is that the the saveAssociated method is saying me that the model couldnt be saved, thanks

I am attaching the code and the bin link http://bin.cakephp.org/view/1231114400
  1. /**
  2. Estimation Model
  3. **/
  4.  
  5. App::uses('AppModel', 'Model');
  6.  
  7. /**
  8. * Estimation Model
  9. *
  10. * @property Referal $Referal
  11. * @property Invoicing $Invoicing
  12. * @property Contract $Contract
  13. * @property SalePackage $SalePackage
  14. */
  15. class Estimation extends AppModel {
  16.  
  17.     /**
  18.      * Validation rules
  19.      *
  20.      * @var array
  21.      */
  22.     public $validate = array(
  23.         'referal_id' => array(
  24.         'numeric' => array(
  25.             'rule' => array('numeric'),
  26.         ),
  27.         ),
  28.         'invoicing_id' => array(
  29.         'numeric' => array(
  30.             'rule' => array('numeric'),
  31.         ),
  32.         ),
  33.         'vehicles_from' => array(
  34.         'numeric' => array(
  35.             'rule' => array('numeric'),
  36.         ),
  37.         ),
  38.         'vehicles_to' => array(
  39.         'numeric' => array(
  40.             'rule' => array('numeric'),
  41.         ),
  42.         ),
  43.         'expiration_days' => array(
  44.         'numeric' => array(
  45.             'rule' => array('numeric'),
  46.         ),
  47.         ),
  48.         'active' => array(
  49.         'boolean' => array(
  50.             'rule' => array('boolean'),
  51.         ),
  52.         ),
  53.         'status' => array(
  54.         'boolean' => array(
  55.             'rule' => array('boolean'),
  56.         ),
  57.         ),
  58.     );
  59.  
  60.     //The Associations below have been created with all possible keys, those that are not needed can be removed
  61.  
  62.     /**
  63.      * belongsTo associations
  64.      *
  65.      * @var array
  66.      */
  67.     public $belongsTo = array(
  68.         'Referal' => array(
  69.         'className' => 'Referal',
  70.         'foreignKey' => 'referal_id',
  71.         'conditions' => '',
  72.         'fields' => '',
  73.         'order' => ''
  74.         ),
  75.         'Invoicing' => array(
  76.         'className' => 'Invoicing',
  77.         'foreignKey' => 'invoicing_id',
  78.         'conditions' => '',
  79.         'fields' => '',
  80.         'order' => ''
  81.         )
  82.     );
  83.  
  84.     /**
  85.      * hasMany associations
  86.      *
  87.      * @var array
  88.      */
  89.     public $hasMany = array(
  90.         'Contract' => array(
  91.         'className' => 'Contract',
  92.         'foreignKey' => 'estimation_id',
  93.         'dependent' => false,
  94.         'conditions' => '',
  95.         'fields' => '',
  96.         'order' => '',
  97.         'limit' => '',
  98.         'offset' => '',
  99.         'exclusive' => '',
  100.         'finderQuery' => '',
  101.         'counterQuery' => ''
  102.         ),
  103.         'SalePackage' => array(
  104.         'className' => 'SalePackage',
  105.         'foreignKey' => 'estimation_id',
  106.         'dependent' => false,
  107.         'conditions' => '',
  108.         'fields' => '',
  109.         'order' => '',
  110.         'limit' => '',
  111.         'offset' => '',
  112.         'exclusive' => '',
  113.         'finderQuery' => '',
  114.         'counterQuery' => ''
  115.         )
  116.     );
  117.  
  118. }
  119.  
  120.  
  121. /**
  122. Method for save data
  123. **/
  124. public function admin_add() {
  125.         if ($this->request->is('post')) {
  126.             //$this->Estimation->create();
  127.             debug($this->request->data);
  128.             if ($this->Estimation->saveAssociated($this->request->data)) {
  129.                 $this->Session->setFlash(__('The estimation has been saved'));
  130.                 /*if (isset($this->request->data['Estimation']['new']) && $this->request->data['Estimation']['new']) {
  131.                     $this->redirect(array('controller' => 'estimations', 'action' => 'add'));
  132.                 } else {
  133.                     $this->redirect(array('controller' => 'estimations', 'action' => 'view', $this->Estimation->id));
  134.                 }*/
  135.             } else {
  136.                 $this->Session->setFlash(__('The estimation could not be saved. Please, try again.'));
  137.             }
  138.         }
  139.  
  140.  
  141. /**
  142. The result  of the array debug before saving
  143. **/
  144.     'Referal' => array(
  145.         'biz_name' => 'EL BANANERO',
  146.         'doc_type_id' => '3',
  147.         'doc_number' => '2141232',
  148.         'first_name' => 'RICARDO',
  149.         'last_name' => 'OVIEDO',
  150.         'address' => 'Arequipa',
  151.         'email' => 'ricardo.oviedo@open-comet.com',
  152.         'phone' => '',
  153.         'mobile' => ''
  154.     ),
  155.     'Estimation' => array(
  156.         'date' => '2012-07-18',
  157.         'invoicing_id' => '1',
  158.         'vehicles_from' => '9',
  159.         'vehicles_to' => '10',
  160.         'expiration_days' => '10',
  161.         'comments' => 'Esto es una prueba',
  162.         'sub_total' => '40',
  163.         'taxes' => '7.2',
  164.         'total' => '47.2',
  165.         'new' => '0'
  166.     ),
  167.     'SalePackage' => array(
  168.         (int) 0 => array(
  169.             'product_id' => '1',
  170.             'description' => 'PRODUCTO UNO',
  171.             'price_package' => '10'
  172.         ),
  173.         (int) 1 => array(
  174.             'product_id' => '1',
  175.             'description' => 'PRODUCTO UNO',
  176.             'price_package' => '10'
  177.         ),
  178.         (int) 2 => array(
  179.             'product_id' => '1',
  180.             'description' => 'PRODUCTO UNO',
  181.             'price_package' => '10'
  182.         ),
  183.         (int) 3 => array(
  184.             'product_id' => '1',
  185.             'description' => 'PRODUCTO UNO',
  186.             'price_package' => '10'
  187.         )
  188.     )
  189. )
--   Carlos Eduardo Sotelo Pinto      GNU Linux Admin | PHP Senior Web Developer      MObil: RPC (Claro)+51, 958194614      http://www.carlossotelo.com      Skype: csotelop      Yahoo: csotelop      MSN: carlos.sotelo.pinto@gmail.com      GTalk: carlos.sotelo.pinto@gmail.com  GPG FP:697E FAB8 8E83 1D60 BBFB 2264 9E3D 5761 F855 4F6B  GNULinux RU #379182 || GNULinux RM #277661

No comments: