01.28 diff saved
hiromi2424
Tags add more
 
Note
hiromi2424 did not leave a note
  1. 1442a1443,1496
  2. >
  3. >         $oldLinks = array();
  4. >         $toDeleteLinks = array();
  5. >
  6. >         if ($this->hasAndBelongsToMany[$assoc]['unique']) {
  7. >           $conditions = array_merge(
  8. >             array($join . '.' . $this->hasAndBelongsToMany[$assoc]['foreignKey'] => $id),
  9. >             (array)$this->hasAndBelongsToMany[$assoc]['conditions']
  10. >           );
  11. >           $links = $this->{$join}->find('all', array(
  12. >             'conditions' => $conditions,
  13. >             'recursive' => empty($this->hasAndBelongsToMany[$assoc]['conditions']) ? -1 : 0,
  14. >             'fields' => $this->hasAndBelongsToMany[$assoc]['associationForeignKey']
  15. >           ));
  16. >
  17. >           $associationForeignKey = "{$join}." . $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
  18. >           $oldLinks = Set::extract($links, "{n}.{$associationForeignKey}");
  19. >          
  20. >           $toDeleteLinks = array();
  21. >          
  22. >           $newLinks = array();
  23. >           foreach((array)$data as $row){
  24. >             $newLink = null;
  25. >            
  26. >             if ((is_string($row) && (strlen($row) == 36 || strlen($row) == 16)) || is_numeric($row)) {
  27. >               $newLink = $row;
  28. >             } elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
  29. >               if(isset($row[$this->{$join}->primaryKey])){
  30. >                 continue;
  31. >               }
  32. >               $newLink = $row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']];
  33. >             } elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
  34. >               if(isset($row[$join][$this->{$join}->primaryKey])){
  35. >                 continue;
  36. >               }
  37. >               $newLink = $row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']];
  38. >             }
  39. >            
  40. >             if(!$newLink){
  41. >               continue;
  42. >             }
  43. >            
  44. >             $newLinks[] = $newLink;
  45. >           }
  46. >           $newLinks = array_unique($newLinks);
  47. >          
  48. >           $toDeleteLinks = array_diff($oldLinks,$newLinks);
  49. >          
  50. >           if (!empty($toDeleteLinks)) {
  51. >        $conditions[$associationForeignKey] = $toDeleteLinks;
  52. >             $db->delete($this->{$join}, $conditions);
  53. >           }
  54. >         }
  55. >
  56. 1444a1499,1501
  57. >             if(in_array($row,$oldLinks)){
  58. >               continue;
  59. >             }
  60. 1455a1513,1516
  61. >             if(in_array($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']],$oldLinks)
  62. >               && !isset($row[$this->{$join}->primaryKey]) ){
  63. >               continue;
  64. >             }
  65. 1457a1519,1522
  66. >             if(in_array($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']],$oldLinks)
  67. >                && !isset($row[$join][$this->{$join}->primaryKey]) ){
  68. >               continue;
  69. >             }
  70. 1461,1479c1526
  71. <
  72. <         if ($this->hasAndBelongsToMany[$assoc]['unique']) {
  73. <           $conditions = array_merge(
  74. <             array($join . '.' . $this->hasAndBelongsToMany[$assoc]['foreignKey'] => $id),
  75. <             (array)$this->hasAndBelongsToMany[$assoc]['conditions']
  76. <           );
  77. <           $links = $this->{$join}->find('all', array(
  78. <             'conditions' => $conditions,
  79. <             'recursive' => empty($this->hasAndBelongsToMany[$assoc]['conditions']) ? -1 : 0,
  80. <             'fields' => $this->hasAndBelongsToMany[$assoc]['associationForeignKey']
  81. <           ));
  82. <
  83. <           $associationForeignKey = "{$join}." . $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
  84. <           $oldLinks = Set::extract($links, "{n}.{$associationForeignKey}");
  85. <           if (!empty($oldLinks)) {
  86. <        $conditions[$associationForeignKey] = $oldLinks;
  87. <             $db->delete($this->{$join}, $conditions);
  88. <           }
  89. <         }
  90. ---
  91. >        
  92. 1492a1540
  93. >        
  94.  
Parsed in 0.028 seconds, using GeSHi 1.0.7.14

Modify this Paste