#6077: Saving a model with a "with association" habtm data results in data loss
---------------------------------+------------------------------------------
    Reporter:  ralph.marchildon  |          Type:  Bug    
      Status:  new               |      Priority:  Medium 
   Milestone:  1.2.x.x           |     Component:  General
     Version:  1.2 Final         |      Severity:  Major  
    Keywords:                    |   Php_version:  n/a    
Cake_version:  1.2.1.8004        |  
---------------------------------+------------------------------------------
 = What I Did =
 Using the latest branch, I reated a normal HABTM relation between Recipe
 and Tag as in the Book.  Created tags, created a recipe and saved the
 recipe with 2 associated tags.  Works perfectly.  Modified the relation to
 contain: 'with' => 'RecipesTag'
 Edited my previous recipe and saved it.  The previously associated Tag
 relations are deleted as expected but are NOT recreated as normal.
 See [http://bin.cakephp.org/view/1466275806] for full details.
 [[BR]][[BR]]


 = What I Expected =
 I expected the framework to re-add the HABTM associations as it normally
 does when a with association is not specified.  Or, at the very least, not
 delete my data, but this would make it inconsistent with the behavior of a
 HABTM when a with association is not specified.[[BR]]
 [[BR]]


 = Problem Code =
 In model.php in `__saveMulti()`, when it's building the array of new data
 to insert after having deleted the data from the join table, it only ever
 expects to find data in the format `$data['Tag']['Tag']` in my case,
 ignoring the newly named with association.
 [[BR]][[BR]]


 = Possible Fix =
 {{{
 } elseif
 
(isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']]))
 {
         $newData[] = $row[$join];
 }}}
 [[BR]]


 = Possible Problems =
 My with association uses a autoincrement pk, this solution does NOT
 preserve the pk.  However, it looks like all the interactions with the
 join table are done via foreign keys.[[BR]]
 [[BR]]

 I've attached a patch for model.test.php covering this test case and a
 patch to model.php that causes the test case to pass.[[BR]]
 [[BR]]
 Thanks to bic2k and the guys on IRC for their help.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/6077>
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 tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
tickets-cakephp+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to