1
我有三個型號,user
,message
和message_reply
:我該如何處理這個活動記錄驗證?
#user.rb
class User < ActiveRecord::Base
has_many :message_replies
has_many :sent_messages, class_name: "Message", foreign_key: :sendor_id
has_many :received_messages, class_name: "Message", foreign_key: :receiver_id
end
#message.rb
class Message < ActiveRecord::Base
belongs_to :Sendor, class_name: "user", foreign_key: :sendor_id
belongs_to :Receiver, class_name: "user", foreign_key: :receiver_id
has_many :message_replies
end
#message_reply.rb
class MessageReply < ActiveRecord::Base
belongs_to :user
belongs_to :message
end
我想驗證在MessageReply
的:user_id
要麼是sendor_id
或Message
實例receiver_id
,這MessageReply
實例所屬。
「MessageReply」的用途是什麼?它是什麼時候創建的?創建時,它是否已經與'message'關聯? – AbM
@AbM'MessageReply'是回覆特定'Message'的模型。它與我在問題中發佈的模型代碼所示的消息具有一對多關係。 –