#4375: Bug in validation coupled with saveAll
-----------------------------------+----------------------------------------
    Reporter:  kiger               |         Owner:          
        Type:  Bug                 |        Status:  reopened
    Priority:  Medium              |     Milestone:  1.2.x.x 
   Component:  Model               |       Version:  RC1     
    Severity:  Normal              |    Resolution:          
    Keywords:  saveall validation  |   Php_version:  n/a     
Cake_version:  1.2.x rev 6595      |  
-----------------------------------+----------------------------------------
Changes (by biesbjerg):

  * status:  closed => reopened
  * resolution:  needmoreinfo =>

Comment:

 Experiencing the same here in 1.2.8004.

 Needs proper test case, but I hope this info can help reproduce the bug.

 Error message:
 {{{
 Warning (2): Cannot use a scalar value as an array
 [CORE/cake/libs/model/model.php, line 1556]

 Code | Context

 $this   =       Customer
 Customer::$name = "Customer"
 Customer::$hasMany = array
 Customer::$validate = array
 Customer::$useDbConfig = "simple_shop"
 Customer::$actsAs = array
 Customer::$useTable = "customers"
 Customer::$displayField = "name"
 Customer::$id = "84"
 Customer::$data = false
 Customer::$table = "customers"
 Customer::$primaryKey = "id"
 Customer::$_schema = array
 Customer::$validationErrors = array
 Customer::$tablePrefix = ""
 Customer::$alias = "Customer"
 Customer::$tableToModel = array
 Customer::$logTransactions = false
 Customer::$transactional = false
 Customer::$cacheQueries = false
 Customer::$belongsTo = array
 Customer::$hasOne = array
 Customer::$hasAndBelongsToMany = array
 Customer::$Behaviors = BehaviorCollection object
 Customer::$whitelist = array
 Customer::$cacheSources = true
 Customer::$findQueryType = NULL
 Customer::$recursive = 1
 Customer::$order = NULL
 Customer::$__exists = NULL
 Customer::$__associationKeys = array
 Customer::$__associations = array
 Customer::$__backAssociation = array
 Customer::$__insertID = "84"
 Customer::$__numRows = NULL
 Customer::$__affectedRows = NULL
 Customer::$_findMethods = array
 Customer::$_log = NULL
 Customer::$Order = Order object
 Customer::$locale = NULL
 $data   =       array(
         "Customer" => array(
         "name" => "Kim",
         "street" => "Dalumvej 41",
         "zip" => "5250",
         "city" => "Odense SV",
         "email" => "[email protected]"
 ),
         "Order" => array(
         "description" => "Slip din eksamensangst (Lydbog)",
         "amount" => 129
 )
 )
 $options        =       array(
         "validate" => true,
         "atomic" => true,
         "validates" => "first"
 )
 $db     =       DboMysqli
 DboMysqli::$description = "Mysqli DBO Driver"
 DboMysqli::$_baseConfig = array
 DboMysqli::$startQuote = "`"
 DboMysqli::$endQuote = "`"
 DboMysqli::$_useAlias = true
 DboMysqli::$_commands = array
 DboMysqli::$columns = array
 DboMysqli::$index = array
 DboMysqli::$alias = "AS "
 DboMysqli::$fieldCache = array
 DboMysqli::$__bypass = false
 DboMysqli::$__sqlOps = array
 DboMysqli::$connected = true
 DboMysqli::$fullDebug = false
 DboMysqli::$error = NULL
 DboMysqli::$affected = 1
 DboMysqli::$numRows = 1
 DboMysqli::$took = 0
 DboMysqli::$_result = mysqli_result object
 DboMysqli::$_queriesCnt = 0
 DboMysqli::$_queriesTime = NULL
 DboMysqli::$_queriesLog = array
 DboMysqli::$_queriesLogMax = 200
 DboMysqli::$_queryCache = array
 DboMysqli::$__descriptions = array
 DboMysqli::$_sources = array
 DboMysqli::$connection = mysqli object
 DboMysqli::$config = array
 DboMysqli::$configKeyName = "simple_shop"
 DboMysqli::$_transactionStarted = true
 DboMysqli::$cacheSources = true
 DboMysqli::$_log = NULL
 DboMysqli::$results = mysqli_result object
 DboMysqli::$map = array
 $validationErrors       =       array()
 $validates      =       true
 $return =       array()
 $associations   =       array(
         "Order" => "hasMany"
 )
 $values =       array(
         "description" => "8lip din eksamensangst (Lydbog)",
         "amount" => 129
 )
 $association    =       "Order"
 $validating     =       false
 $type   =       "hasMany"
 $value  =       129
 $i      =       "amount"

                         case 'hasMany':

                             foreach ($values as $i => $value) {

 $values[$i][$this->{$type}[$association]['foreignKey']] =  $this->id;

 Model::saveAll() - CORE/cake/libs/model/model.php, line 1556
 CheckoutController::_process_step_1() -
 APP/plugins/simple_shop/controllers/checkout_controller.php, line 48
 WizardComponent::process() - CORE/controllers/components/wizard.php, line
 143
 CheckoutController::wizard() -
 APP/plugins/simple_shop/controllers/checkout_controller.php, line 34
 Object::dispatchMethod() - CORE/cake/libs/object.php, line 119
 Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 245
 Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 211
 [main] - APP/webroot/index.php, line 96

 Warning (2): Cannot modify header information - headers already sent by
 (output started at /opt/lampp/htdocs/kosmoscms2/www/cake/basics.php:111)
 [CORE/cake/libs/controller/controller.php, line 615]
 }}}

 The 2 models:
 {{{
 <?php
 class Customer extends SimpleShopAppModel {
         var $name = 'Customer';

         var $hasMany = array(
                 'Order' => array(
                         'className' => 'SimpleShop.Order',
                         'foreignKey' => 'customer_id',
                         'dependent' => true
                 )
         );

         var $validate = array(
                 'name' => 'notEmpty',
                 'street' => 'notEmpty',
                 'zip' => 'numeric',
                 'city' => 'notEmpty',
                 'email' => 'email',
         );
 }
 ?>
 }}}

 {{{
 <?php
 class Order extends SimpleShopAppModel {
         var $name = 'Order';

         var $belongsTo = array(
                 'Customer' => array(
                         'className' => 'SimpleShop.Customer',
                         'foreignKey' => 'customer_id'
                 )
         );

         var $validate = array(
                 'customer_id' => array(
                         'required' => true,
                         'rule' => 'notEmpty'
                 )
         );
 }
 ?>
 }}}

 Data to be saved:

 {{{
 Array
 (
     [Customer] => Array
         (
             [name] => Kim
             [street] => Dalumvej 41
             [zip] => 5250
             [city] => Odense SV
             [email] => [email protected]
         )

     [Order] => Array
         (
             [description] => Slip din eksamensangst (Lydbog)
             [amount] => 129
         )

 )
 }}}

 Controller:

 {{{
 <?php
 class CheckoutController extends SimpleShopAppController {
         var $name = 'Checkout';
         var $uses = array('SimpleShop.Customer');

         function step1() {
                 $this->data['Order'] = array(
                         'description' =>
 Configure::read('Fribetaling.product.description'),
                         'amount' =>
 Configure::read('Fribetaling.product.amount')
                 );

                 if ($this->Customer->saveAll($this->data,
 array('validates' => 'first')) !== true) {
                         die('error');
                 }

                 $this->Session->write('Checkout.orderNumber',
 $this->Customer->Order->id);
         }
 }
 ?>
 }}}

-- 
Ticket URL: <https://trac.cakephp.org/ticket/4375#comment:6>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to