Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules
Commits
410ff7a6
Commit
410ff7a6
authored
Sep 06, 2018
by
Zach Perkins
Browse files
Used more efficient ActiveRecord create
parent
cc4f4bdc
Changes
1
Hide whitespace changes
Inline
Side-by-side
schedules_api/db/seeds.rb
View file @
410ff7a6
...
...
@@ -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,6 +51,23 @@ total.each do |subject, sections|
next
end
section_name
=
"
#{
section
[
:subj
]
}
#{
section
[
:course_number
]
}
#{
section
[
:section
]
}
"
all_sections
.
push
({
name:
section_name
,
crn:
section
[
:crn
],
section_type:
section
[
:type
],
title:
section
[
:title
],
instructor:
section
[
:instructor
],
start_date:
section
[
:start_date
],
end_date:
section
[
:end_date
],
days:
section
[
:days
],
start_time:
section
[
:start_time
],
end_time:
section
[
:end_time
],
location:
section
[
:location
],
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
...
...
@@ -58,25 +77,12 @@ total.each do |subject, sections|
course
.
semester
=
semester
course
.
save!
section_name
=
"
#{
section
[
:subj
]
}
#{
section
[
:course_number
]
}
#{
section
[
:section
]
}
"
# puts "Adding #{section_name}..."
CourseSection
.
create!
(
name:
section_name
,
crn:
section
[
:crn
],
section_type:
section
[
:type
],
title:
section
[
:title
],
instructor:
section
[
:instructor
],
start_date:
section
[
:start_date
],
end_date:
section
[
:end_date
],
days:
section
[
:days
],
start_time:
section
[
:start_time
],
end_time:
section
[
:end_time
],
location:
section
[
:location
],
course:
course
)
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment