Created
July 30, 2019 16:21
-
-
Save krokrob/4ce3d16dc68b2be02a206646465ed6f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Rake tasks | |
# db:create => create empty DB | |
# db:migrate => update DB schema (structure) | |
# db:seed => populate the DB (data) | |
# db:drop => !!!!! drop the DB (structure + data) | |
# | |
class Restaurant < ActiveRecord::Base | |
end | |
restaurant = Restaurant.new # => instance of restaurant | |
restaurant.save #=> save in DB | |
restaurant.update(column: value) #=> update in DB | |
restaurant.name #=> return name | |
restaurant.name = 'new value' #=> update value | |
restaurant.save #=> save in DB | |
restaurant.destroy | |
Restaurant.all #=> all instance of Restaurant [] (ActiveRecord::Relation?) | |
Restaurant.find(id) #=> find ONE instance with id | |
Restaurant.where(condition) #=> [instance of Restaurant] | |
# condition: (name: 'Alicheur') | |
# condition: ('name LIKE ?', 'Esprit%') | |
# condition: ('created_at > ?', Date.today - 1.day) | |
Restaurant.find_by(column: value) #=> find ONE instance | |
Restaurant.first | |
Restaurant.last | |
Restaurant.count | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment