-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from LaunchCodeEducation/chapter18
Chapter 18: Relationships and ORM
- Loading branch information
Showing
39 changed files
with
1,261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: "Chapter 18: Relationships in Object-Relational Mapping" | ||
date: 2023-08-21T14:38:32-05:00 | ||
draft: false | ||
weight: 18 | ||
originalAuthor: Sally Steuterman # to be set by page creator | ||
originalAuthorGitHub: gildedgardenia # to be set by page creator | ||
reviewer: # to be set by the page reviewer | ||
reviewerGitHub: # to be set by the page reviewer | ||
lastEditor: # update any time edits are made after review | ||
lastEditorGitHub: # update any time edits are made after review | ||
lastMod: # UPDATE ANY TIME CHANGES ARE MADE | ||
--- | ||
|
||
## Learning Objectives | ||
|
||
Upon completing the content in this chapter, you should be able to do the following: | ||
|
||
1. Build persistent model classes that have one-to-many, many-to-one, one-to-one, and many-to-many relationships | ||
1. Understand how these relationships are represented in a relational database | ||
|
||
## Key Terminology | ||
|
||
As you read though this chapter, make note of the following key terms and their definitions. | ||
|
||
### Types of Relationships | ||
|
||
1. one-to-one relationship | ||
1. one-to-many relationship | ||
1. many-to-one relationship | ||
1. many-to-many relationship | ||
|
||
### Creating a Many-to-One Relationship | ||
|
||
1. truncate | ||
|
||
### Creating a One-to-One Relationship | ||
|
||
1. transient | ||
1. cascades | ||
|
||
### Creating a Many-to-Many Relationship | ||
|
||
1. data transfer object | ||
1. DTO | ||
1. join table | ||
|
||
## Chapter Content | ||
|
||
{{% children %}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: "Exercises: The Early Bird Gets the ORM!" | ||
date: 2023-08-21T14:38:32-05:00 | ||
draft: false | ||
weight: 2 | ||
originalAuthor: Sally Steuterman # to be set by page creator | ||
originalAuthorGitHub: gildedgardenia # to be set by page creator | ||
reviewer: # to be set by the page reviewer | ||
reviewerGitHub: # to be set by the page reviewer | ||
lastEditor: # update any time edits are made after review | ||
lastEditorGitHub: # update any time edits are made after review | ||
lastMod: # UPDATE ANY TIME CHANGES ARE MADE | ||
--- | ||
|
||
Now that we have gotten very familiar with our `coding-events` application, let's design some additional features. | ||
As you work on your `coding-events` application, you may have been inspired by [Meetup](https://www.meetup.com/)! | ||
One of the cool features that Meetup has is that people can sign up for accounts. | ||
They can use their Meetup accounts to follow the events they are most interested in and keep track of their calendar of events. | ||
To add similar features to `coding-events`, you need to add a `Person` class. | ||
For the exercises, answer the following questions about what your `Person` class would look like. | ||
|
||
{{% notice blue "Note" "rocket" %}} | ||
You do not have to code anything to complete these exercises! | ||
This is mainly focused on using our design skills to add a new feature to your application. | ||
{{% /notice %}} | ||
|
||
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? | ||
1. Would you need to add any additional classes to `Person` to make the app work? If so, what classes would be necessary? | ||
1. What kinds of relationships would `Person` have to the other classes you already created, such as the `Event` class? | ||
|
||
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! | ||
|
||
1. Add a `README.md` to your repository by navigating to the repository page on your GitHub profile. | ||
At the bottom of the page, there is a blue banner asking you to add a `README.md`. Click the button to do so! | ||
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. | ||
The third and final section should describe the future improvements you want to make to the app including your notes about the `Person` class. | ||
|
||
{{% expand "Check your solution" %}} | ||
|
||
Here is an example of how the README may turn out: | ||
|
||
1. Our `Person` class might hold the following fields: | ||
|
||
1. `id` (`int`) - the unique user ID | ||
1. `firstName` (`String`) - the user’s first name | ||
1. `lastName` (`String`) - the user’s last name | ||
1. `email` (`String`) - the user’s email, which will also function as their username | ||
1. `password` (`String`) - the user’s password | ||
|
||
The class would need getters for all of these fields. It could have setters for all fields except id (since it shouldn’t change). | ||
|
||
1. The Person class might also have the following references: | ||
|
||
1. `PersonProfile` - a class to gather up all of the profile information about the user | ||
1. `List<Events> eventsAttending` - to store events the user wants to attend | ||
1. `List<Events> eventsOwned` - a different list, to store the events the user has created | ||
|
||
`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`. | ||
|
||
{{% /expand %}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: "Next Steps" | ||
date: 2023-08-21T14:38:32-05:00 | ||
draft: false | ||
weight: 3 | ||
originalAuthor: Sally Steuterman # to be set by page creator | ||
originalAuthorGitHub: gildedgardenia # to be set by page creator | ||
reviewer: # to be set by the page reviewer | ||
reviewerGitHub: # to be set by the page reviewer | ||
lastEditor: # update any time edits are made after review | ||
lastEditorGitHub: # update any time edits are made after review | ||
lastMod: # UPDATE ANY TIME CHANGES ARE MADE | ||
--- | ||
|
||
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. | ||
|
||
1. [Spring ORM Example Using Hibernate](https://www.geeksforgeeks.org/spring-orm-example-using-hibernate/) | ||
1. [Spring Documentation](https://docs.spring.io/spring-framework/docs/2.0.x/reference/orm.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: "Reading" | ||
date: 2023-08-21T14:38:32-05:00 | ||
draft: false | ||
weight: 1 | ||
originalAuthor: Sally Steuterman # to be set by page creator | ||
originalAuthorGitHub: gildedgardenia # to be set by page creator | ||
reviewer: # to be set by the page reviewer | ||
reviewerGitHub: # to be set by the page reviewer | ||
lastEditor: # update any time edits are made after review | ||
lastEditorGitHub: # update any time edits are made after review | ||
lastMod: # UPDATE ANY TIME CHANGES ARE MADE | ||
--- | ||
|
||
## Reading Content Links | ||
|
||
{{% children %}} |
Oops, something went wrong.