diff --git a/app/models/course.rb b/app/models/course.rb index a26e2828..a829760d 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -14,6 +14,8 @@ class Course < ActiveRecord::Base before_create :set_access_code + default_scope -> { order(:created_at) } + def self.find_by_identifier!(identifier) where('access_code = ? OR uuid = ?', identifier, identifier).first! end diff --git a/db/migrate/20150310175830_add_index_on_created_at_to_courses.rb b/db/migrate/20150310175830_add_index_on_created_at_to_courses.rb new file mode 100644 index 00000000..a7ad1fb9 --- /dev/null +++ b/db/migrate/20150310175830_add_index_on_created_at_to_courses.rb @@ -0,0 +1,5 @@ +class AddIndexOnCreatedAtToCourses < ActiveRecord::Migration + def change + add_index :courses, :created_at + end +end diff --git a/db/schema.rb b/db/schema.rb index 6044feca..9df3a055 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150305150214) do +ActiveRecord::Schema.define(version: 20150310175830) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -87,6 +87,7 @@ t.string "access_code" end + add_index "courses", ["created_at"], name: "index_courses_on_created_at", using: :btree add_index "courses", ["organization_id"], name: "index_courses_on_organization_id", using: :btree add_index "courses", ["teacher_id"], name: "index_courses_on_teacher_id", using: :btree add_index "courses", ["uuid"], name: "index_courses_on_uuid", unique: true, using: :btree