Skip to content

Commit 627b18c

Browse files
Merge pull request #35 from LaunchCodeEducation/chapter18
Chapter 18: Relationships and ORM
2 parents 2aa2a82 + 9b04e5b commit 627b18c

39 files changed

Lines changed: 1261 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: "Chapter 18: Relationships in Object-Relational Mapping"
3+
date: 2023-08-21T14:38:32-05:00
4+
draft: false
5+
weight: 18
6+
originalAuthor: Sally Steuterman # to be set by page creator
7+
originalAuthorGitHub: gildedgardenia # to be set by page creator
8+
reviewer: # to be set by the page reviewer
9+
reviewerGitHub: # to be set by the page reviewer
10+
lastEditor: # update any time edits are made after review
11+
lastEditorGitHub: # update any time edits are made after review
12+
lastMod: # UPDATE ANY TIME CHANGES ARE MADE
13+
---
14+
15+
## Learning Objectives
16+
17+
Upon completing the content in this chapter, you should be able to do the following:
18+
19+
1. Build persistent model classes that have one-to-many, many-to-one, one-to-one, and many-to-many relationships
20+
1. Understand how these relationships are represented in a relational database
21+
22+
## Key Terminology
23+
24+
As you read though this chapter, make note of the following key terms and their definitions.
25+
26+
### Types of Relationships
27+
28+
1. one-to-one relationship
29+
1. one-to-many relationship
30+
1. many-to-one relationship
31+
1. many-to-many relationship
32+
33+
### Creating a Many-to-One Relationship
34+
35+
1. truncate
36+
37+
### Creating a One-to-One Relationship
38+
39+
1. transient
40+
1. cascades
41+
42+
### Creating a Many-to-Many Relationship
43+
44+
1. data transfer object
45+
1. DTO
46+
1. join table
47+
48+
## Chapter Content
49+
50+
{{% children %}}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: "Exercises: The Early Bird Gets the ORM!"
3+
date: 2023-08-21T14:38:32-05:00
4+
draft: false
5+
weight: 2
6+
originalAuthor: Sally Steuterman # to be set by page creator
7+
originalAuthorGitHub: gildedgardenia # to be set by page creator
8+
reviewer: # to be set by the page reviewer
9+
reviewerGitHub: # to be set by the page reviewer
10+
lastEditor: # update any time edits are made after review
11+
lastEditorGitHub: # update any time edits are made after review
12+
lastMod: # UPDATE ANY TIME CHANGES ARE MADE
13+
---
14+
15+
Now that we have gotten very familiar with our `coding-events` application, let's design some additional features.
16+
As you work on your `coding-events` application, you may have been inspired by [Meetup](https://www.meetup.com/)!
17+
One of the cool features that Meetup has is that people can sign up for accounts.
18+
They can use their Meetup accounts to follow the events they are most interested in and keep track of their calendar of events.
19+
To add similar features to `coding-events`, you need to add a `Person` class.
20+
For the exercises, answer the following questions about what your `Person` class would look like.
21+
22+
{{% notice blue "Note" "rocket" %}}
23+
You do not have to code anything to complete these exercises!
24+
This is mainly focused on using our design skills to add a new feature to your application.
25+
{{% /notice %}}
26+
27+
1. You need to add a `Person` class to hold necessary info about users of our app. What fields and methods would this class hold?
28+
1. Would you need to add any additional classes to `Person` to make the app work? If so, what classes would be necessary?
29+
1. What kinds of relationships would `Person` have to the other classes you already created, such as the `Event` class?
30+
31+
As you dream up answers to these questions, write the answers down in a note or piece of paper. You are now going to write up some documentation for your app!
32+
33+
1. Add a `README.md` to your repository by navigating to the repository page on your GitHub profile.
34+
At the bottom of the page, there is a blue banner asking you to add a `README.md`. Click the button to do so!
35+
1. You should write three sections. The first should describe the purpose of the app. The second should describe the current state of the app.
36+
The third and final section should describe the future improvements you want to make to the app including your notes about the `Person` class.
37+
38+
{{% expand "Check your solution" %}}
39+
40+
Here is an example of how the README may turn out:
41+
42+
1. Our `Person` class might hold the following fields:
43+
44+
1. `id` (`int`) - the unique user ID
45+
1. `firstName` (`String`) - the user’s first name
46+
1. `lastName` (`String`) - the user’s last name
47+
1. `email` (`String`) - the user’s email, which will also function as their username
48+
1. `password` (`String`) - the user’s password
49+
50+
The class would need getters for all of these fields. It could have setters for all fields except id (since it shouldn’t change).
51+
52+
1. The Person class might also have the following references:
53+
54+
1. `PersonProfile` - a class to gather up all of the profile information about the user
55+
1. `List<Events> eventsAttending` - to store events the user wants to attend
56+
1. `List<Events> eventsOwned` - a different list, to store the events the user has created
57+
58+
`Person` would have a many-to-many relationship with `Event` via `List<Events> eventsAttending`. It would have a one-to-many relationship with `Event` via `List<Events> eventsOwned`.
59+
60+
{{% /expand %}}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: "Next Steps"
3+
date: 2023-08-21T14:38:32-05:00
4+
draft: false
5+
weight: 3
6+
originalAuthor: Sally Steuterman # to be set by page creator
7+
originalAuthorGitHub: gildedgardenia # to be set by page creator
8+
reviewer: # to be set by the page reviewer
9+
reviewerGitHub: # to be set by the page reviewer
10+
lastEditor: # update any time edits are made after review
11+
lastEditorGitHub: # update any time edits are made after review
12+
lastMod: # UPDATE ANY TIME CHANGES ARE MADE
13+
---
14+
15+
After completing this chapter, you are ready to tackle authentication. If you would like to learn more about Spring and ORM, here are a few resources.
16+
17+
1. [Spring ORM Example Using Hibernate](https://www.geeksforgeeks.org/spring-orm-example-using-hibernate/)
18+
1. [Spring Documentation](https://docs.spring.io/spring-framework/docs/2.0.x/reference/orm.html)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "Reading"
3+
date: 2023-08-21T14:38:32-05:00
4+
draft: false
5+
weight: 1
6+
originalAuthor: Sally Steuterman # to be set by page creator
7+
originalAuthorGitHub: gildedgardenia # to be set by page creator
8+
reviewer: # to be set by the page reviewer
9+
reviewerGitHub: # to be set by the page reviewer
10+
lastEditor: # update any time edits are made after review
11+
lastEditorGitHub: # update any time edits are made after review
12+
lastMod: # UPDATE ANY TIME CHANGES ARE MADE
13+
---
14+
15+
## Reading Content Links
16+
17+
{{% children %}}

0 commit comments

Comments
 (0)