Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## User Model
- class User < ActiveRecord::Base
- has_many :articles, :dependent => :destroy
- end
- ## Article Model
- class Article < ActiveRecord::Base
- belongs_to :user
- end
- ## IRB
- irb(main):002:0> u = User.find(:first)
- => #<User id: 1, username: "Blinchik", password: "1234", created_at: "2008-04-19 17:57:24", updated_at: "2008-04-19 17:57:24">
- irb(main):007:0> a = u.articles.create(:author => u.username, :title => "JHGhgas")
- => #<Article id: nil, author: "Blinchik", title: "JHGhgas", body: nil, user_id: 1, created_at: nil, updated_at: nil>
- irb(main):007:0> a.save
- => nil
- irb(main):008:0> Article.find(:all)
- => []
Add Comment
Please, Sign In to add comment