ADD model ProjectCategory

This commit is contained in:
Jasder 2019-11-07 11:15:41 +08:00
parent dce8c2f776
commit d16faf40af
4 changed files with 32 additions and 2 deletions

View File

@ -42,7 +42,8 @@ class Project < ActiveRecord::Base
indexes :updated_on, index:"not_analyzed", type:'date'
end
end
belongs_to :project_category , :counter_cache => true
has_many :student_work_projects, :dependent => :destroy
has_many :contestant_work_projects, :dependent => :destroy
has_many :student_works

View File

@ -0,0 +1,6 @@
# 项目类别
class ProjectCategory < ActiveRecord::Base
attr_accessible :name, :position, :projects_count
has_many :projects
end

View File

@ -0,0 +1,15 @@
class CreateProjectCategories < ActiveRecord::Migration
def change
create_table :project_categories do |t|
t.string :name
t.integer :position
t.integer :projects_count, :default => 0
t.timestamps
end
names = %w(大数据 机器学习 深度学习 人工智能 量子计算 智慧医疗 自动驾驶 其他)
names.each do |name|
ProjectCategory.where(name: name).first_or_create
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20191026085118) do
ActiveRecord::Schema.define(:version => 20191107015025) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1974,6 +1974,14 @@ ActiveRecord::Schema.define(:version => 20191026085118) do
t.datetime "updated_at", :null => false
end
create_table "project_categories", :force => true do |t|
t.string "name"
t.integer "position"
t.integer "projects_count", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "project_infos", :force => true do |t|
t.integer "project_id"
t.integer "user_id"