Ruby
1class User < ActiveRecord::Base 2 has_many :microposts, dependent: :destroy 3 has_many :relationships, foreign_key: "follower_id",dependent: :destroy 4 has_many :followed_users, through: :relationships, source: :followed 5 has_many :reverse_relationships, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy 6 has_many :followers, through: :reverse_relationships, source: :follower 7end
- Railsチュートリアル(http://railstutorial.jp/)より、Userモデル設計についてご質問です
- 上述しているように、UsersテーブルはMicropostsと1対多、ユーザーをフォローする/されるを表現するために、Relationshipsテーブルを作って多対多を表現しています
- 質問内容としては、「このユーザモデルが持つ実装上の懸念点は何か考えよ」という課題の回答がわからないのでもしどなたかわかるかたがいらっしゃればご教示いただきたいです
あなたの回答
tips
プレビュー