Pergunta de entrevista da empresa OpenTable

Q. There are a couple of errors with this Ruby code. What are they? users = User.where(active: true) Post = [ ] users.each do |user| Post << user.posts end

Resposta da entrevista

Sigiloso

15 de fev. de 2016

A. The interviewer said that the only problem was that there are actually a million users and it's not optimized. The answer the interviewer provided: posts = Post.joins(:user).where(active: true) users = User.where(active: true).includes(:posts)

1