当前位置: 动力学知识库 > 问答 > 编程问答 >

php - MySQL - Updating a model with children within children

问题描述:

I am trying to create a schedule; each schedule has many shifts, and each shift has many tasks. The user is able to create as many shifts/tasks as they want. They can modify the tasks by resizing them or moving them to another shift.

When I want to update the schedule, I have two choices:

  1. Delete all the old entries, and simply re-enter all the new ones
  2. Loop through all the new shifts, and try to find them in the table. If a match is found, then update, if not create a new one. And then I need to loop through all the tasks for that shift, and try to do the same (this I have no idea how to do it, since a task that may have been for shift_1 could now be part of shift_2).

So my question is this: is it an overkill of MySQL entries if I just delete all the old rows and enter the ones?

网友答案:

It really depends. Are other things referencing your entries, and thus your keys? If so, search and replace is your only option (because you really DON'T want to rebuild indices if you have help it).

If nothing is directly referencing the keys, however, emptying and rebuilding the table is the fastest option available to you.

分享给朋友:
您可能感兴趣的文章:
随机阅读: