Web アプリ用のプライベート メッセージング システムを作成しています。Facebook や Twitter などの一般的なソーシャル ネットワーキング Web サイトで PM を送信したり、Hotmail で電子メールを送信したりするのと同じことを考えてみてください。
I have come up with the following migration so far:
class CreateMessages < ActiveRecord::Migration
def self.up
create_table :messages do |t|
t.integer :sender_id, :recipient_id
t.string :title
t.text :body
t.boolean :read
t.timestamps
end
end
def self.down
drop_table :messages
end
end
ただし、sender_id と recipient_id は両方とも、Role モデルの id フィールドである同じフィールドを参照します。インタープリターがそのフィールドを参照していることを認識するために、どのような変更を加える必要がありますか。テーブルの結合など、他に必要な変更はありますか?