#5722: UUID HABTM Link model doesn't use Model save process as numeric ID does
---------------------------------------------+------------------------------
    Reporter:  rafaelbandeira3               |         Owner:          
        Type:  Bug                           |        Status:  reopened
    Priority:  High                          |     Milestone:  1.2.x.x 
   Component:  Model                         |       Version:  RC2     
    Severity:  Major                         |    Resolution:          
    Keywords:  model habtm save uuid 'with'  |   Php_version:  n/a     
Cake_version:                                |  
---------------------------------------------+------------------------------
Changes (by rafaelbandeira3):

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

Comment:

 Actually the assumption that the title of the ticket does is incorrect.
 What happens in Model::__saveMulti() is that the most common HABTM post
 data format
 {{{
 $data['Model']['Model'] = array(1, 2, 3, 4, 5, 6);
 }}}
 Is processed directly by the DboSource::insertMulti without using the link
 model, letting no chance
 for callbacks to take their hands on the data about to be saved nor in the
 record just saved,
 While the more common format
 {{{
 $data['Model'][0]['model_id'] = 1;
 $data['Model'][1]['model_id'] = 2;
 $data['Model'][2]['model_id'] = 3;
 $data['Model'][3]['model_id'] = 4;
 }}}
 that is not used on HABTM is saved by the normal process.

 Saving the HABTM common data set:
 {{{
         if ((is_string($row) && (strlen($row) == 36 || strlen($row) ==
 16)) || is_numeric($row)) {
                 $values = array(
                         $db->value($id,
 $this->getColumnType($this->primaryKey)),
                         $db->value($row)
                 );
                 [...]
                 $values = join(',', $values);
                 $newValues[] = "({$values})";
         [...]
         if (!empty($newValues)) {
                 $fields =  array(
 $db->name($this->hasAndBelongsToMany[$assoc]['foreignKey']),
 $db->name($this->hasAndBelongsToMany[$assoc]['associationForeignKey'])
                 );
                 if ($isUUID) {
                         $fields[] = $db->name($this->{$join}->primaryKey);
                 }
                 $fields =  join(',', $fields);
                 $db->insertMulti($this->{$join}, $fields, $newValues);
         }
 }}}
 and the other...
 {{{
         } elseif
 (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']]))
 {
                 $newData[] = $row;
         }
         [...]
         if (!empty($newData)) {
                 foreach ($newData as $data) {
 $data[$this->hasAndBelongsToMany[$assoc]['foreignKey']] = $id;
                         $this->{$join}->create($data);
                         $this->{$join}->save();
                 }
         }
 }}}

 I think that independently of the way the data is posted, it should always
 pass
 by the default save process, allowing the extensibility of the data
 mapping by
 enabling callback calls.

 So the propose is to change the title of the ticket to "HABTM data saving
 should use the default saving process"
 but to maintain it as a 1.2 feature, wich means "a bug" for now.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5722#comment:2>
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