Looking at Documentation is an important part of programming. You don't have to memorize anything, but you should get familiar with the types of information you can find in different docs. For this exercise, using the ActiveRecord documentation here, take a look at the following methods:
find
.find_by
.where
.all
.first
.destroy
With your table mates and answer the following questions about each methods
- What argument or arguments does the method take?
- What type of object does the method return?
- What happens if none of the parameters match? (i.e. what if
Tweet.find(5)
can't find that tweet? How aboutTweet.find_by(id: 6)
?
Pretend that you have a tweets
table with two columns - message
and user_id
. Given the code below, write in a notebook or on a whiteboard what SQL statements will fire when the following methods are called?
class Tweet < ActiveRecord::Base
end
Tweet.all
Tweet.find(5)
Tweet.find_by(user_id: 7)
Tweet.where(user_id: 7)
Tweet.create(user_id: 5, message: 'making some coffee')
Tweet.destroy(7)