【发布时间】:2011-01-10 16:02:19
【问题描述】:
我希望在我的网站中实现一个 facebook 风格的消息传递系统(线程消息)。
你认为这个架构标记看起来不错吗?
学说 schema.yml:
UserMessage:
tableName: user_message
actAs: [Timestampable]
columns:
id: { type: integer(10), primary: true, autoincrement: true }
sender_id : { type: integer(10), notnull: true }
sender_read: { type: boolean, default: 1 }
subject: { type: string(255), notnull: true }
message: { type: string(1000), notnull: true }
hash: { type: string(32), notnull: true }
relations:
UserMessageRecipient as Recipient:
type: many
local: id
foreign: message_id
UserMessageReply as Reply:
type: many
local: id
foreign: message_id
UserMessageReply:
tableName: user_message_reply
columns:
id: { type: integer(10), primary: true, autoincrement: true }
user_message_id as message_id: { type: integer(10), notnull: true }
message: { type: string(1000), notnull: true }
sender_id: { type: integer(10), notnull: true }
relations:
UserMessage as Message:
local: message_id
foreign: id
type: one
UserMessageRecipient:
tableName: user_message_recipient
actAs: [Timestampable]
columns:
id: { type: integer(10), primary: true, autoincrement: true }
user_message_id as message_id: { type: integer(10), notnull: true }
recipient_id: { type: integer(10), notnull: true }
recipient_read: { type: boolean, default: 0 }
当我做出新的回复时,我会确保每个收件人的“recipient_read”布尔值设置为 false,当然我也会确保 sender_read 也设置为 false。
我正在为 URL 使用哈希:http://example.com/user/messages/aadeb18f8bdaea49882ec4d2a8a3c062
(由于 id 将从 1 开始,我不希望有 http://example.com/user/messages/1。是的,我可以从更大的数字开始递增,但我更喜欢从 1 开始。)
这是一个好方法吗?您的想法和建议将不胜感激。
谢谢大家!
【问题讨论】:
-
UserMessage 和 UserMessageReply 都代表一个类 - 消息。我会创建一个类并通过reply_id 字段将其与自身相关联。在此处阅读有关嵌套关系的信息:doctrine-project.org/projects/orm/1.2/docs/manual/…
-
啊,有趣。非常感谢。
-
你用这个了吗?它是在 Rails 3 中完成的吗?
标签: mysql database-design symfony1 doctrine