Ihor0k

Untitled

May 10th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. Есть такая бд:
  2.  
  3. employee:
  4. +----+----------------+-------------------+-------------+
  5. | id | name | email | skype_id |
  6. +----+----------------+-------------------+-------------+
  7. | 1 | Ivan Petrov | petrov@mail.ru | ivan_petrov |
  8. | 2 | Dmitry Voronov | dmitry@mail.ru | dm_dm |
  9. | 3 | Elena Smirnova | smirnova@area9.dk | smir-el |
  10. +----+----------------+-------------------+-------------+
  11.  
  12. project:
  13. +----+---------+-------------+
  14. | id | name | description |
  15. +----+---------+-------------+
  16. | 1 | Drive | d |
  17. | 2 | Essence | e |
  18. | 3 | AdWords | a |
  19. +----+---------+-------------+
  20.  
  21.  
  22. allocation:
  23. +----+------+----------+---------+------------------+
  24. | id | week | employee | project | work_description |
  25. +----+------+----------+---------+------------------+
  26. | * | * | * | * | * |
  27. +----+------+----------+---------+------------------+
  28.  
  29. Вот так сейчас работает обычный дропдаун:
  30.  
  31. === CASE 1 ===
  32.  
  33. // меняем выбранный элемент дропдауна в репорте
  34. +----------------+--------+ +----------------+---------+
  35. | | week 1 | | | week 1 |
  36. +----------------+--------+ ===> +----------------+---------+
  37. | Elena Smirnova | Pick | | Elena Smirnova | AdWords |
  38. +----------------+--------+ +----------------+---------+
  39.  
  40. // изменения в бд
  41. Add record:
  42. +----+------+----------+---------+------------------+
  43. | id | week | employee | project | work_description |
  44. +----+------+----------+---------+------------------+
  45. | 1 | 1 | 3 | 3 | NULL |
  46. +----+------+----------+---------+------------------+
  47.  
  48. === CASE 2 ===
  49.  
  50. +-------------+--------+ +-------------+---------+
  51. | | week 1 | | | week 1 |
  52. +-------------+--------+ ===> +-------------+---------+
  53. | Ivan Petrov | Drive | | Ivan Petrov | AdWords |
  54. +-------------+--------+ +-------------+---------+
  55.  
  56. Update record (work_description остается прежним):
  57. +----+------+----------+---------+------------------+ +----+------+----------+---------+------------------+
  58. | id | week | employee | project | work_description | | id | week | employee | project | work_description |
  59. +----+------+----------+---------+------------------+ ===> +----+------+----------+---------+------------------+
  60. | 1 | 1 | 1 | 1 | d1 | | 1 | 1 | 1 | 3 | d1 |
  61. +----+------+----------+---------+------------------+ +----+------+----------+---------+------------------+
  62.  
  63. Так будет если добавить мультиселект дропдаун:
  64.  
  65. === CASE 1 ===
  66.  
  67. +----------------+--------+ +----------------+----------------+
  68. | | week 1 | | | week 1 |
  69. +----------------+--------+ ===> +----------------+----------------+
  70. | Elena Smirnova | Pick | | Elena Smirnova | Drive, AdWords |
  71. +----------------+--------+ +----------------+----------------+
  72.  
  73. Add record:
  74. +----+------+----------+---------+------------------+
  75. | id | week | employee | project | work_description |
  76. +----+------+----------+---------+------------------+
  77. | 1 | 1 | 3 | 1 | NULL |
  78. | 2 | 1 | 3 | 3 | NULL |
  79. +----+------+----------+---------+------------------+
  80.  
  81.  
  82. === CASE 2 ===
  83.  
  84. +-------------+--------+ +-------------+---------+
  85. | | week 1 | | | week 1 |
  86. +-------------+--------+ ===> +-------------+---------+
  87. | Ivan Petrov | Drive | | Ivan Petrov | AdWords |
  88. +-------------+--------+ +-------------+---------+
  89.  
  90. Delete record:
  91. +----+------+----------+---------+------------------+
  92. | id | week | employee | project | work_description |
  93. +----+------+----------+---------+------------------+
  94. | 1 | 1 | 1 | 1 | d1 |
  95. +----+------+----------+---------+------------------+
  96.  
  97. Add record:
  98. +----+------+----------+---------+------------------+
  99. | id | week | employee | project | work_description |
  100. +----+------+----------+---------+------------------+
  101. | 2 | 1 | 1 | 3 | NULL |
  102. +----+------+----------+---------+------------------+
  103.  
  104. === CASE 3 ===
  105.  
  106. allocation:
  107. +----+------+----------+---------+------------------+
  108. | id | week | employee | project | work_description |
  109. +----+------+----------+---------+------------------+
  110. | 1 | 1 | 1 | 1 | d1 |
  111. | 2 | 1 | 1 | 2 | d2 |
  112. +----+------+----------+---------+------------------+
  113.  
  114. +-------------+-----------------+ +-------------+------------------+
  115. | | week 1 | | | week 1 |
  116. +-------------+-----------------+ ===> +-------------+------------------+
  117. | Ivan Petrov | Drive, Essence | | Ivan Petrov | Essence, AdWords |
  118. +-------------+-----------------+ +-------------+------------------+
  119.  
  120. Delete record:
  121. +----+------+----------+---------+------------------+
  122. | id | week | employee | project | work_description |
  123. +----+------+----------+---------+------------------+
  124. | 1 | 1 | 1 | 1 | d1 |
  125. +----+------+----------+---------+------------------+
  126.  
  127. Add record:
  128. +----+------+----------+---------+------------------+
  129. | id | week | employee | project | work_description |
  130. +----+------+----------+---------+------------------+
  131. | 3 | 1 | 1 | 3 | NULL |
  132. +----+------+----------+---------+------------------+
  133.  
  134.  
  135. Проблема в том, что в case2 и case3 теряется work_description. Использовать в case2 UPDATE вместо DELETE+ADD — не вариант, поскольку вместо одного AdWords может быть выбранно несколько проектов (как в case3). И тут уже ставить для всех записей work_description = d1 неправильно, т.к. в удаленных записях может быть и d1, и d2.
Add Comment
Please, Sign In to add comment