Answer the question
In order to leave comments, you need to log in
How to store tasks and subtasks in the database?
For practice in studying, I decided to write a todo application in which there are tasks with subtasks. But I ran into such a problem that I can’t figure out how to store tasks and subtasks in the database.
I thought about two options:
For tasks and subtasks, one common table, where there will be a field with the id of the parent, and specify null for parents
Or two different tables
I would like to know if there are any other options?
Answer the question
In order to leave comments, you need to log in
In theory, you can still try graphs and linked lists. It seems to be redundant within todo. Although, if you pick in the direction of connections between subtasks of different tasks, then it may be appropriate. For example, the task "have dinner" has a subtask "go to the store for buckwheat", and another task (independent) has a subtask "go to the store for toilet paper". If the application tells you to combine these two subtasks, it will be nice. I would solve through linked tables, but only because I didn’t work with graphs and linked lists.
Depends on what business tasks solve tasks and subtasks. Generate a list of task and subtask attributes and compare the two sets. If they are equal, then into one table and the foreign key is on itself. If the sets are not equal, then in different tables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question