Skip to content

Instantly share code, notes, and snippets.

@arunagw
arunagw / Trying Mongoid embeds_many
Created February 9, 2011 13:55
Trying Mongoid embeds_many
ruby-1.9.2-p0 > b = Blog.create(:title => "This is blog")
=> #<Blog _id: 4d529be33e4dd32664000002, title: "This is blog">
ruby-1.9.2-p0 > Blog.count
=> 1
ruby-1.9.2-p0 > b.comments.create(:body => "This is body")
=> #<Comment _id: 4d529bf63e4dd32664000003, body: "This is body">
ruby-1.9.2-p0 > b.comments.count
=> 1
ruby-1.9.2-p0 > reload!
Reloading...
ruby-1.9.2-p0 > b = Blog.first
=> #<Blog _id: 4d529be33e4dd32664000002, title: "This is blog">
ruby-1.9.2-p0 > b.comments.length
=> 0
ruby-1.9.2-p0 > b.comments.create(:body => "New body again")
=> #<Comment _id: 4d529f0c3e4dd329a9000001, body: "New body again">
ruby-1.9.2-p0 > b.comments.count
=> 1
ruby-1.9.2-p0 > b.comments.clear
=> []