Skip to content

Instantly share code, notes, and snippets.

@vannell
Last active December 18, 2015 11:39
Show Gist options
  • Save vannell/5777103 to your computer and use it in GitHub Desktop.
Save vannell/5777103 to your computer and use it in GitHub Desktop.
rails console
user = User.new
user.orders << Order.create!
user.save
#will create a User with a single new Order
rails generate model User
rails generate model Order user_id:integer
rake db:migrate
#app/models/user.rb
class User < ActiveRecord::Base
has_many :orders
end
#app/models/order.rb
class Order < ActiveRecord::Base
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment