Skip to content

Commit 165f6d6

Browse files
committed
still fixing models
1 parent e82e2b9 commit 165f6d6

File tree

9 files changed

+852
-33
lines changed

9 files changed

+852
-33
lines changed

app/models/catalog.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
class Catalog < ApplicationRecord
2+
has_many :catalog_courses
3+
has_many :courses, through: :catalog_courses
4+
has_many :requirements
5+
has_many :plans
26
end

app/models/category.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class Category < ApplicationRecord
22
belongs_to :requirements
3+
has_many :category_courses
4+
has_many :courses, through: :category_courses
35
end

app/models/course.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
class Course < ApplicationRecord
22
has_many :plan_courses
33
has_many :plans, through: :plan_courses
4+
5+
has_many :catalog_courses
6+
has_many :catalogs, through: :catalog_courses
7+
8+
has_many :category_courses
9+
has_many :categories, through: :category_courses
410
end

app/models/major.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class Major < ApplicationRecord
2+
has_many :users
3+
has_many :plans
4+
has_many :requirements
25
end

app/models/plan.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Plan < ApplicationRecord
2-
belongs_to(:user)
2+
belongs_to :user
3+
belongs_to :major
4+
belongs_to :catalog
35
has_many :plan_courses
46
has_many :courses, through: :plan_courses
57
end

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ class User < ApplicationRecord
44
devise :database_authenticatable, :registerable,
55
:recoverable, :rememberable, :validatable
66
has_many(:plans)
7-
7+
belongs_to :major
88
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddRoleToUsers < ActiveRecord::Migration[6.0]
2+
def change
3+
add_column :users, :role, :string
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2020_04_23_021033) do
13+
ActiveRecord::Schema.define(version: 2020_04_23_021526) do
1414

1515
create_table "catalog_courses", force: :cascade do |t|
1616
t.integer "catalog_id", null: false
@@ -102,6 +102,7 @@
102102
t.datetime "updated_at", precision: 6, null: false
103103
t.string "login"
104104
t.integer "major_id"
105+
t.string "role"
105106
t.index ["email"], name: "index_users_on_email", unique: true
106107
t.index ["login"], name: "index_users_on_login", unique: true
107108
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

0 commit comments

Comments
 (0)