Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Last active December 27, 2015 17:18
Show Gist options
  • Save laspluviosillas/7360694 to your computer and use it in GitHub Desktop.
Save laspluviosillas/7360694 to your computer and use it in GitHub Desktop.
Interview Question #2
# (Rails 3.2)
# Number of Units in the system: 30,000
# Number of Courses in the system: 50.
# Unit:
# Properties
# -- active: boolean
# -- course_id: int
class Unit < ActiveRecord::Base
attr_accessible :active
belongs_to :course
end
# Course:
class Course < ActiveRecord::Base
has_many :units
end
# This code finds all the ids of courses associated to *active* units.
Unit.where(active: true).all.map(&:course_id).uniq
# What is the main problem with the line above?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment