LoginSignup
0
1

More than 1 year has passed since last update.

Rials いいね・コメント・フォロー・メール・チャットのテーブル設計

Posted at

ユーザーと投稿物(book)

  create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.string "name"
    t.text "introduction"
    t.string "profile_image_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

  create_table "books", force: :cascade do |t|
    t.string "title"
    t.text "body"
    t.integer "user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

いいね機能


  create_table "favorites", force: :cascade do |t|
    t.integer "user_id"
    t.integer "book_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

コメント機能


  create_table "book_comments", force: :cascade do |t|
    t.text "comment"
    t.integer "user_id"
    t.integer "book_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

フォロー機能


  create_table "relationships", force: :cascade do |t|
    t.integer "follower_id"
    t.integer "followed_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

 メール機能(+アドレス機能)


  create_table "mail", force: :cascade do |t|
    t.integer "user_id"
    t.integer "target_user_id"
    t.integer "target_user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "adrresses", force: :cascade do |t|
    t.integer "from_user_id"
    t.integer "to_user_id"
    t.string "title"
    t.text "body"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

チャット機能

LINEのように相互に、時系列も分かるようなビューを搭載するなら、chat_roomという概念を入れたほうがわかりやすい。
メールは、誰々からのメッセージを見ると言った感じで、受信履歴(相手からのみ)を見る。
対して、チャットルームを導入すれば、そのチャットルームを上から順に出力すれば、勝手に相互時系列になる。


  create_table "caht_rooms", force: :cascade do |t|
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "chat_room_users", force: :cascade do |t|
    t.integer "chat_room_id"  # どこで
    t.integer "user_id"     # 誰が(いる)
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "chat_messages", force: :cascade do |t|
    t.integer "chat_room_id" # どこで
    t.integer "user_id" # 誰が
    t.text "body"     # 何言った
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end


0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1