如何在数据库中设置不同的消息 post 类型

How to setup different message post types in a database

我正在为新闻应用构建提要。

我可以做一个 单张 post 包含 2 张卡片。有图片卡,有文字卡。我作为用户,可以按我想要的任何顺序创建两张卡片的 post。在我执行 post 后,其他用户可以看到我的 post 包含我 post 编辑它们的顺序中的两张卡片。

如何在数据库中进行设置?这是我目前所拥有的。

一个用户可以做很多 posts,但是我用什么关系来表明 Post 包含特定顺序的 2 个对象(顺便说一句,在真实的应用程序中,有超过 2 种消息类型) . Post 可以任意组合。它可以包含 2 个文本,或 2 个图像,或图像和文本,或文本和图像的组合。

您需要一个名为 post_items 的新 table - 它将有 4 列:

POST_ID - foreign key into table POST
ITEM_TYPE_ID - ENUM, determining which table the column ITEM_ID is foreign key into
ITEM_ID - foreign key into either TextPost, ImagePost or any other desired table
ITEM_ORDER - defines the order of the item inside the post