Skip to content

Instantly share code, notes, and snippets.

@dsazup
Last active July 22, 2020 21:47
Show Gist options
  • Save dsazup/93015f25194a928f2378c9587b12dfbb to your computer and use it in GitHub Desktop.
Save dsazup/93015f25194a928f2378c9587b12dfbb to your computer and use it in GitHub Desktop.
<%= @user_assignments.each do |assignment| %>
assignment.steps.size -- will do query for each assignment
It would be nice to do something like
@user_assignments.preload_counts(:steps) and then just do assignment.steps_count
<% end %>
class Assignment < ApplicationRecord
belongs_to :course
belongs_to :user
has_many :steps, through: :course
end
class Course < ApplicationRecord
belongs_to :course
has_many :steps
end
class Step < ApplicationRecord
belongs_to :course
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment