parent
6334df531e
commit
a5c941f48c
@ -0,0 +1,12 @@
|
|||||||
|
class CourseMessage < ActiveRecord::Base
|
||||||
|
attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed
|
||||||
|
|
||||||
|
# 多态 虚拟关联
|
||||||
|
belongs_to :course_message ,:polymorphic => true
|
||||||
|
belongs_to :course
|
||||||
|
belongs_to :user
|
||||||
|
validates :user_id,presence: true
|
||||||
|
validates :course_id,presence: true
|
||||||
|
validates :course_message_id,presence: true
|
||||||
|
validates :course_message_type, presence: true
|
||||||
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class CreateCourseMessages < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :course_messages do |t|
|
||||||
|
t.integer :user_id
|
||||||
|
t.integer :course_id
|
||||||
|
t.integer :course_message_id
|
||||||
|
t.string :course_message_type
|
||||||
|
t.integer :viewed
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :course_message do
|
||||||
|
user_id 1
|
||||||
|
course_id 1
|
||||||
|
course_message_id 1
|
||||||
|
course_message_type "MyString"
|
||||||
|
viewed 1
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in new issue