On Mon, Aug 17, 2015 at 1:18 AM, Scott Goci <[email protected]> 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.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAHxKQig7nArZkWijmui4wmrmuwnDBKk3J809G92pZojoBVEAFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to