Last active
December 27, 2015 17:18
-
-
Save laspluviosillas/7360694 to your computer and use it in GitHub Desktop.
Interview Question #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (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