Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created July 30, 2019 16:21
Show Gist options
  • Save krokrob/4ce3d16dc68b2be02a206646465ed6f9 to your computer and use it in GitHub Desktop.
Save krokrob/4ce3d16dc68b2be02a206646465ed6f9 to your computer and use it in GitHub Desktop.
# 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