- [] Recognize the connection between the primary key - foreign key relationship and ActiveRecord associations
- [] Implement a one to many association between two models
- [] Implement a one to one association between two models
- [] Read and understand documentation on ActiveRecord association methods
- RailsGuides on ActiveRecord
- RailsGuides on ActiveRecord Migrations
- RailsGuides for ActiveRecord Query Interface
- RailsGuides for ActiveRecord Associations
- Rails documentation (section on ActiveRecord)
- APIDock has_many
- APIDock belongs_to
- VSCode Sqlite Extension
...
...
...
- Create
Walk
model and associatedwalks
table - open up
./bin/console
and do create a couple of dogs.
- Create an
issues
table with the following columns:
- title (string)
- description (string)
- resolved (boolean)
- started_at (datetime)
- computer (belongs_to)
-
In
lib/issue.rb
, create anIssue
class that inherits fromActiveRecord::Base
-
Use an ActiveRecord association macro to create a relationship between an issue and a computer. Which type of relationship should you add here?
-
Enter
./bin/console
and create a couple of issues for thefirst_computer
. Use Sqlite Explorer to check your database to ensure the issues are created.
...
...
When you use the association method to access the related computer, what does the SQL query look like?
...
- Finish adding the one-to-many relationship between
Dog <== Walk
-
Update the Computer class to add an ActiveRecord association method that relates the Computer model to the Issue model.
-
Open up
./bin/console
and use it to create an issue for a computer and then access that computer and view all of its issues. Confirm that you're able to call a method on either the issue or the computer and see the other object in the return value.
...
...
...