Guest User

Untitled

a guest
Apr 25th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. ## User Model
  2. class User < ActiveRecord::Base
  3. has_many :articles, :dependent => :destroy
  4. end
  5.  
  6. ## Article Model
  7. class Article < ActiveRecord::Base
  8. belongs_to :user
  9. end
  10.  
  11. ## IRB
  12. irb(main):002:0> u = User.find(:first)
  13. => #<User id: 1, username: "Blinchik", password: "1234", created_at: "2008-04-19 17:57:24", updated_at: "2008-04-19 17:57:24">
  14. irb(main):007:0> a = u.articles.create(:author => u.username, :title => "JHGhgas")
  15. => #<Article id: nil, author: "Blinchik", title: "JHGhgas", body: nil, user_id: 1, created_at: nil, updated_at: nil>
  16. irb(main):007:0> a.save
  17. => nil
  18. irb(main):008:0> Article.find(:all)
  19. => []
Add Comment
Please, Sign In to add comment