0

我正在为游戏构建一种留言板系统,但在建模关系时遇到了问题。这是我到目前为止所拥有的:

Models
------
User (Has Many Posts)
Post (Belongs to User, Belongs to Game)
Game (Has Many Posts)

这是我需要添加的内容。

Models
------
Server (Belongs to Game but also part of Post)
Replies (Belongs to Post and Post's User but needs to function like private messaging)

对这两件事进行建模的最简单方法是什么?我对服务器的最佳猜测是:

Server - Has Many Posts, Belongs To Game
Posts - Belongs To Server
Game - Has Many Servers

我什至不知道从哪里开始回复。帖子和用户将有许多回复,但回复将有两个用户和一个帖子。谢谢。

4

1 回答 1

0

我用这些关系解决了这个问题:

模型服务器

belongs_to :game
has_many :posts

模型游戏

has_many :posts
has_many :servers

模型回复

belongs_to :post
belongs_to :poster, class_name: :user, foreign_key: :poster_id
belongs_to :replier, class_name: :user, foreign_key: :replier_id

模型柱

belongs_to :user
belongs_to :game
belongs_to :server
has_many :replies, dependent: :destroy

模型用户

has_many :posts, dependent: :destroy
has_many :replies, dependent: :destroy
于 2012-09-11T20:27:05.710 回答