- [] 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 a
computers
table with the following columns:
- brand (string)
- model (string)
- screen_size (float)
- model_year (integer)
- asleep (boolean)
- last_backed_up_at (datetime)
-
In
lib/computer.rb
, create aComputer
class that inherits fromActiveRecord::Base
-
In
lib/exercises.rb
fill in thefirst_computer
andsecond_computer
methods so that they both return computers withbrand
,model
,screen_size
andmodel_year
properties assigned.
...
Why do we write database changes to a file instead of using SQL to update the structure of the database?
...
...
...
...
...
For this, let's open up ./bin/console
and attempt the following:
-
Define a
back_up
method within the computer class that updates thelast_backed_up_at
attribute of the computer to the current date and time. -
Define a
sleep
method within the computer class that updates theasleep
attribute of the computer totrue
. -
Define a
wake_up
method within the computer class that updates theasleep
attribute of the computer tofalse
. -
Define a
backed_up
method within the computer class that returns all of the computers that have been backed_up.
...
...
...