0
我有一個對話ActiveRecord的模型,它本質上是計算領域ActiveRecord的基於協會
class Conversation < ActiveRecord::Base
has_many :messages, :order => 'created_at ASC'
belongs_to :latest_message, :class_name => 'Message'
end
我想latest_message屬性始終設置爲messages.last以下。我試過before_save回調,但似乎並沒有被解僱,當我添加一條消息時,如
conversation.messages.create!(
sender: user,
body: message_body
)
任何想法?