TABLE presentation {
    id BIGINT
    unique_id BIGINT
    name VARCHAR (128)
    description VARCHAR (256)
    updated_at TIMESTAMP
    created_at TIMESTAMP
}


我正在创建一个允许用户创建演示文稿的应用程序。每个演示文稿都构建在一个布局中,每个布局包含多个位置,每个位置都由资产(文本,图像,视频)占据。

我正在尝试找出在演示文稿,布局和资产之间建立联系的最佳方法。

最初,我在考虑为presentationslayoutspositionsassets创建一个表。我显然需要此架构灵活,因此我可以添加几个具有不同位置数的新layouts

我可以像这样创建我的presentation表:

TABLE presentation {
    id BIGINT
    unique_id BIGINT
    name VARCHAR (128)
    description VARCHAR (256)
    position1 (BIGINT) - would contain an asset_id
    position2 (BIGINT) - would contain an asset_id
    position3 (BIGINT) - would contain an asset_id
    position4 (BIGINT) - would contain an asset_id
    updated_at TIMESTAMP
    created_at TIMESTAMP
}


但这是非常短视的,并且只允许一个演示文稿中的4个总职位...但是我现在将继续处理更大或更坏的事情。

或者,我以某种方式在presentationslayoutspositionsassets之间建立了连接,这将提供总体灵活性...这就是我试图寻求帮助的地方。

我不太确定是否要考虑这个问题……最重要的是,我真的不确定如何在这些模型之间建立正确的连接。

最佳答案

您的示例中的结构将适合于子表,例如:

TABLE presentation_position {
   presentation_id (BIGINT)
   position (INT)
   asset_id (BIGINT)
}


您可以通过id列(或unique_id)将其加入到演示文稿中,也可以仅通过presentation_id查询以按位置顺序获取asset_id值序列。就像是:

select position, asset_id from presentation_position where presentation_id = 555 order by position


编辑:

通过您的其他评论,我对您的意图有了更好的了解。我认为您只需要一种结构来保留资产在页面上的位置。像这样:

TABLE presentation_element {
   presentation_id (BIGINT)
   sequence (INT)
   xpos (INT)
   ypos (INT)
   asset_id (BIGINT)
}


您还可以根据需要添加框高度,宽度等的列。 presentation_id和sequence列应为唯一键。因此,预设101将具有以下行:

101   1  100  100  19     //place asset 19 at 100,100
101   2  255  20   102    //place asset 102 at 255,20

关于php - 组织数据库结构,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23485067/

10-09 08:33
查看更多