Commit 410ff7a6 authored by Zach Perkins's avatar Zach Perkins
Browse files

Used more efficient ActiveRecord create

parent cc4f4bdc
......@@ -41,6 +41,8 @@ Semester.delete_all
semester = Semester.create! season: 'Fall', year: 2018
semester.save!
all_sections = []
total.each do |subject, sections|
puts "Adding courses for #{subject}..."
sections.each do |section|
......@@ -49,20 +51,10 @@ total.each do |subject, sections|
next
end
# Find or create a course and set its semester
# TODO: this breaks when you try to do more than one semester,
# since just the subject + course_number do not uniquely identify a course
# Check the semester as well
course = Course.find_or_create_by(subject: section[:subj],
course_number: section[:course_number])
course.semester = semester
course.save!
section_name = "#{section[:subj]} #{section[:course_number]} #{section[:section]}"
# puts "Adding #{section_name}..."
CourseSection.create!(name: section_name,
all_sections.push({
name: section_name,
crn: section[:crn],
section_type: section[:type],
title: section[:title],
......@@ -73,10 +65,24 @@ total.each do |subject, sections|
start_time: section[:start_time],
end_time: section[:end_time],
location: section[:location],
course: course)
course: course
})
# Find or create a course and set its semester
# TODO: this breaks when you try to do more than one semester,
# since just the subject + course_number do not uniquely identify a course
# Check the semester as well
course = Course.find_or_create_by(subject: section[:subj],
course_number: section[:course_number])
course.semester = semester
course.save!
# puts "Adding #{section_name}..."
end
end
CourseSection.create!(all_sections)
# create closures for the days there will be no classes
# see: https://registrar.gmu.edu/calendars/fall-2018/
Closure.create! date: Date.new(2018, 9, 3), semester: semester
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment