A person belongs to one Fitbit and a Fitbit belongs to one person.
A article of clothing belongs to a person and a person has many articles of clothing.
A movie could have many genres and a genre could have many movies.
The table name would be movie_genres
.
- When writing tests we may want to clean the database after each test so we have a dedicated database called test just for that.
- We use the development database when we want to get an a real world experience of how our app functions without messing around with real user data.
- The production database is used in the real world that contains real user data that should not be tampered with.
$ rails new appname -d postgresql
- A model file
- A migration file
- A model test file
- A text fixture file
rails g model
creates all associated files (test files, model and migration) while rails g migration
just creates the migratio file (w/o timestamps).
#Imagine that the items
table has a category called quantity
. What command would you type if you wanted to get rid of the quantity
attribute?
$ rails g migration RemoveQuantityFromItems quantity:integer
Imagine that you have a table students
. What is the ActiveRecord query that would return all students
with the first name of Richard?
Student.where(first_name: "Richard")
Student.find(4).update(phone_number: "101-222-3333")
Student.update(4, phone_number: "101-222-3333")
student = Student.find(4)
student.phone_number = "101-222-3333"
student.save