Last active
December 18, 2015 11:39
-
-
Save vannell/5777103 to your computer and use it in GitHub Desktop.
This file contains 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
rails console | |
user = User.new | |
user.orders << Order.create! | |
user.save | |
#will create a User with a single new Order |
This file contains 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
rails generate model User | |
rails generate model Order user_id:integer | |
rake db:migrate |
This file contains 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
#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