almost 5 years ago
models/Post.rb
# nested includes
@posts = current_user.posts.includes( :comments => :user)

# nested joins
@posts = current_user.posts.joins( :comments => :user)

請參考

for includes
http://stackoverflow.com/questions/8554498/rails-includes-nested-relations

for joins
http://stackoverflow.com/questions/8075883/rails-nested-joins

← ubuntu12.04+rvm+passenger+nginx Rails連線SQLserver →