TABLE presentation {
id BIGINT
unique_id BIGINT
name VARCHAR (128)
description VARCHAR (256)
updated_at TIMESTAMP
created_at TIMESTAMP
}
我正在创建一个允许用户创建演示文稿的应用程序。每个演示文稿都在一个布局中构建,每个布局包含多个位置,每个位置都由一个资产(文本,图像,视频)占据。
我正试图找出在演示文稿,布局和资产之间建立联系的最佳方式。
最初,我考虑为presentations
,layouts
,positions
,assets
提供一个表格。我显然需要这个架构是灵活的,所以我可以添加几个具有不同位置的新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个位置...但是我现在正在前往更大更糟糕的事情。
或者,我以某种方式在presentations
,layouts
,positions
和assets
之间建立联系,以实现完全的灵活性......这就是我的意思试图得到一些帮助。
我不太确定我是否在考虑这个问题,或者不是......最重要的是,我真的不确定如何在这些模型之间建立正确的连接。
答案 0 :(得分:1)
示例中的结构适用于子表,如:
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
答案 1 :(得分:0)
正在接听
*仍有工作要做,但需要作者提供更多意见
我想要的结构对我来说还不是很清楚,但是当你首先设置你的实现时,你会先想到一个草图,然后才开始考虑数据库列。
如果您使用Eloquent,它看起来像这样:
用户
class User extends Eloquent {
protected $table = 'users';
public function presentations() {
return $this->hasMany('Presentation');
}
}
演示
class Presentation extends Eloquent {
protected $table = 'presentations';
public function user() {
return $this->belongsTo('User');
}
}
布局
class Layout extends Eloquent {
protected $table = 'layouts';
public function positions() {
return $this->hasMany('Position');
}
}
位置
class Layout extends Eloquent {
protected $table = 'positions';
public function layout() {
return $this->belongsTo('Layout');
}
}
资产
class Asset extends Eloquent {
protected $table = 'assets';
public function layout() {
return $this->belongsTo('Layout');
}
}