Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.35 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. mongoid - using includes to select children objects in a 1..N referenced relationship
  2. blog.posts
  3.        
  4. tag.posts
  5.        
  6. Post.includes(:tag).where(:blog_id: blog.id)
  7.        
  8. blog.posts
  9.        
  10. has_many :posts do
  11.   def with_tags
  12.     includes(:tag)
  13.   end
  14. end
  15.        
  16. blog.posts.with_tags
  17.        
  18. blog.posts
  19.        
  20. class Post
  21.    belongs_to :tag
  22.    default_scope includes(:tag)
  23. end