You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ada-project-docs/wave_06.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,25 +2,27 @@
2
2
3
3
## Goal
4
4
5
-
Our users want to associate tasks and goals. Specifically, our users want to designate that there are many tasks that serve one goal.
5
+
Our users want to associate `Task`s and `Goal`s. Specifically, our users want to designate that there are many tasks that serve one goal.
6
6
7
7
This wave focuses on creating a one-to-many relationship between goals and tasks, where a goal has-many tasks, and a task belongs to one goal.
8
8
9
9
When we have many tasks and many goals, users will want to conveniently gather all of the tasks associated with one goal. Our API should serve this information with a new route, `/goals/<goal_id>/tasks`.
10
10
11
11
## Requirements
12
12
13
-
First, we should update our models so that the relationship is saved in our database.
13
+
First, we should update our models so that the relationship between them is created in our database.
14
14
15
15
Secondly, we should create our new route, `/goals/<goal_id>/tasks`, so that our API gives back the right information.
16
16
17
+
Use the tests in `tests/test_wave_06.py` to guide your implementation.
18
+
- Some tests use a fixture named `one_task_belongs_to_one_goal` that is defined in `tests/conftest.py`.
19
+
- This fixture uses other fixtures to save a task and a goal to the test database, then associates the task with the goal, and stores that updated relationship in the test database.
20
+
17
21
### Tips
18
22
19
23
- Use lesson materials and independent research to review how to set up a one-to-many relationship in Flask.
20
-
- Remember to run `flask db migrate` and `flask db upgrade` whenever there is a change to the model.
24
+
- Remember to run `flask db migrate` and `flask db upgrade` whenever there is a change to a model.
21
25
- Pay attention to the exact shape of the expected JSON. Double-check nested data structures and the names of the keys for any misspellings.
22
-
- Use the tests in `tests/test_wave_06.py` to guide your implementation.
23
-
- Some tests use a fixture named `one_task_belongs_to_one_goal` that is defined in `tests/conftest.py`. This fixture saves a task and a goal to the test database, and uses SQLAlchemy to associate the goal and task together.
24
26
25
27
### Updates to the Goal Model
26
28
@@ -37,8 +39,6 @@ After reviewing the strategy for creating a one-to-many relationship, in the Tas
37
39
- Setting the foreign key to `goal`'s primary key column
38
40
- Using `Optional` syntax to make the attribute nullable
39
41
40
-
Remember to run `flask db migrate` and `flask db upgrade` whenever there is a change to the model.
41
-
42
42
### Sending a List of Task IDs to a Goal
43
43
44
44
Given:
@@ -54,7 +54,7 @@ When I send a `POST` request to `/goals/1/tasks` with this request body:
54
54
}
55
55
```
56
56
57
-
Then the three `Task`s belong to the `Goal` and it gets updated in the database, and we get back a `200 OK` with the following response body:
57
+
Then the three `Task`s belong to the `Goal` and it gets updated in the database. We get back a `200 OK` with the following response body:
58
58
59
59
```json
60
60
{
@@ -102,7 +102,7 @@ then I get this response:
102
102
}
103
103
```
104
104
105
-
Notice that if we have been using a model helper method to return a dictionary representation of a Task, we can use this method to help build this route response. However, we must notice that there is an additional key in the data for the Task models that are associated with the Goal. This doesn't necessarily mean that we should abandon the model helper method, but we may need to introduce logic to allow it to work in this context.
105
+
Notice that if we have been using a model helper method to return a dictionary representation of a Task, we can use this method to help build this route response.
106
106
107
107
This is also true of the Goal model helper method. We may need to introduce logic to allow it to work in this context, or use the existing method to generate the basic dictionary representation of the Goal and then add the additional data for the associated Task models.
0 commit comments