On Mon, Aug 17, 2015 at 1:18 AM, Scott Goci <
sco...@gmail.com> wrote:
> I've been wrestling with database normalization and the "Rails Way" and I
> wanted to get peoples opinions as to if there's a best practices guide to
> how to do it.
IMHO best practice is to keep it properly normalized until you've
identified some need to denormalize. Usually this is due to
performance... and identified through benchmarking with a profiler, as
any human's guess as to why an app is slow is most likely wrong. If
you do have a performance problem, and you think denormalization would
help, consider other approaches first, or possibly whether your app
doesn't need it to be relational in the first place and might benefit
from a non-relational approach. (That's not *quite* the same thing as
"NoSQL".)
> class StudentExam < ActiveRecord::Base
This name tells us nothing. I'd recommend something like
"ExamTaking". (Might also have this include the date or some such
differentiator, in case the student takes the same exam multiple
times.)
> @questions = @exam.questions
> @responses = Response.where(question_id: @questions.pluck(:id)
> @evaluations = Evaluation.where(response_id: @responses.pluck(:id)
>
> This seems kind of painful
Right. I think you need to look at the "includes" method.
--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com,
Blog.Codosaur.us, and Dare2XL.com.