puts"We can load a post through its comment (no magic here)."
showpost=comment_one.post
puts"Commenters are also authors."
comment_two['commenter'].drink_scotch
comment_one['commenter'].drink_scotch
comment_three['commenter'].drink_scotch
puts"\nLet's save an author to her own document."
jane=comment_two['commenter']
jane.save
showjane
puts"Oh, that's neat! Because Ruby passes hash valuee by reference, Jane's new id has been added to the comment she left."
showcomment_two
puts"Of course, we'd better remember to save it."
comment_two.save
showcomment_two
puts"Oooh, denormalized... feel the burn!"
puts
puts
puts
puts"Act II: Views"
puts
puts
sleep2
puts"Let's find all the comments that go with our post."
puts"Our post has id #{post.id}, so lets find all the comments with that post_id."
puts
classComment
view_by:post_id
end
comments=Comment.by_post_id:key=>post.id
showcomments
puts"That was too easy."
puts"We can even wrap it up in a finder on the Post class."
puts
classPost
defcomments
Comment.by_post_id:key=>id
end
end
showpost.comments
puts"Gimme 5 minutes and I'll roll this into the framework. ;)"
puts
puts"There is a lot more that can be done with views, but a lot of the interesting stuff is joins, which of course range across types. We'll pick up where we left off, next time."