新的老师布置的作业表添加,以及相关关系定义

sw_new_course
sw 10 years ago
parent ee5efab7b8
commit a43a6289e4

@ -10,7 +10,7 @@ class Course < ActiveRecord::Base
#belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
has_many :bid
# has_many :bid
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'
has_many :member_principals, :class_name => 'Member',
@ -18,7 +18,7 @@ class Course < ActiveRecord::Base
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
has_many :principals, :through => :member_principals, :source => :principal
has_many :users, :through => :members
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
# has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :homework_for_courses, :dependent => :destroy
has_many :student, :class_name => 'StudentsForCourse', :source => :user
@ -29,6 +29,8 @@ class Course < ActiveRecord::Base
has_many :news, :dependent => :destroy, :include => :author
has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy
has_many :homework_commons, :dependent => :destroy
has_many :course_groups, :dependent => :destroy
acts_as_taggable

@ -0,0 +1,7 @@
#老师布置的作业表
class HomeworkCommon < ActiveRecord::Base
attr_accessible :name, :user_id, :description, :publish_time, :end_time, :homework_type, :late_penalty, :course_id
belongs_to :course
belongs_to :user
end

@ -75,13 +75,15 @@ class User < Principal
has_many :homework_users
has_many :homework_attaches, :through => :homework_users
has_many :homework_evaluations
#问卷相关关关系
has_many :poll_users, :dependent => :destroy
has_many :poll_votes, :dependent => :destroy
has_many :poll, :dependent => :destroy #用户创建的问卷
has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷
# end
#作业相关关系
has_many :homework_commons, :dependent => :destroy
#end
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
:after_remove => Proc.new {|user, group| group.user_removed(user)}
@ -92,7 +94,7 @@ class User < Principal
belongs_to :auth_source
belongs_to :ucourse, :class_name => 'Course', :foreign_key => :id #huang
## added by xianbo for delete
has_many :biding_projects, :dependent => :destroy
# has_many :biding_projects, :dependent => :destroy
has_many :contesting_projects, :dependent => :destroy
belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy
##ended by xianbo
@ -100,7 +102,7 @@ class User < Principal
#####fq
has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy
has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy
has_many :bids, :foreign_key => 'author_id', :dependent => :destroy
# has_many :bids, :foreign_key => 'author_id', :dependent => :destroy
has_many :contests, :foreign_key => 'author_id', :dependent => :destroy
has_many :softapplications, :foreign_key => 'user_id', :dependent => :destroy
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
@ -257,16 +259,6 @@ class User < Principal
end
end
# 判断用户是否加入了竞赛中 fq
def join_in_contest?(bid)
joined = JoinInContest.where('user_id = ? and bid_id =?', self.id, bid.id)
if joined.size > 0
true
else
false
end
end
### fq
def join_in?(course)
joined = StudentsForCourse.where('student_id = ? and course_id = ?', self.id, course.id)

@ -0,0 +1,16 @@
class CreateHomeworkCommons < ActiveRecord::Migration
def change
create_table :homework_commons do |t|
t.string :name
t.integer :user_id
t.text :description
t.date :publish_time
t.date :end_time
t.integer :homework_type, default: 1
t.string :late_penalty
t.integer :course_id
t.timestamps
end
end
end

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150514133640) do
ActiveRecord::Schema.define(:version => 20150519012744) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -541,9 +541,21 @@ ActiveRecord::Schema.define(:version => 20150514133640) do
t.integer "is_teacher_score", :default => 0
end
add_index "homework_attaches", ["bid_id"], :name => "bid_id"
add_index "homework_attaches", ["bid_id"], :name => "index_homework_attaches_on_bid_id"
create_table "homework_commons", :force => true do |t|
t.string "name"
t.integer "user_id"
t.text "description"
t.date "publish_time"
t.date "end_time"
t.integer "type", :default => 1
t.string "late_penalty"
t.integer "course_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "homework_evaluations", :force => true do |t|
t.string "user_id"
t.string "homework_attach_id"
@ -556,9 +568,7 @@ ActiveRecord::Schema.define(:version => 20150514133640) do
t.integer "bid_id"
end
add_index "homework_for_courses", ["bid_id"], :name => "bid_id"
add_index "homework_for_courses", ["bid_id"], :name => "index_homework_for_courses_on_bid_id"
add_index "homework_for_courses", ["course_id"], :name => "course_id"
add_index "homework_for_courses", ["course_id"], :name => "index_homework_for_courses_on_course_id"
create_table "homework_users", :force => true do |t|
@ -1163,14 +1173,12 @@ ActiveRecord::Schema.define(:version => 20150514133640) do
create_table "students_for_courses", :force => true do |t|
t.integer "student_id"
t.integer "course_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "student_idCopy"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "students_for_courses", ["course_id"], :name => "index_students_for_courses_on_course_id"
add_index "students_for_courses", ["student_id"], :name => "index_students_for_courses_on_student_id"
add_index "students_for_courses", ["student_id"], :name => "student_id"
create_table "taggings", :force => true do |t|
t.integer "tag_id"

Loading…
Cancel
Save