2014-05-06 294 views
0
TABLE presentation { 
    id BIGINT 
    unique_id BIGINT 
    name VARCHAR (128) 
    description VARCHAR (256) 
    updated_at TIMESTAMP 
    created_at TIMESTAMP 
} 

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

我想弄清楚在演示文稿,布局和资产之间建立连接的最佳方法。

最初,我在考虑为presentations,layouts,positionsassets设置一个表格。我显然需要这个模式是灵活的,所以我可以添加几个新的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之间的连接将允许完全的灵活性......,这就是我试图得到一些帮助。

我不太清楚,如果我在想这个,或者不是......底线是我真的不知道如何在这些模型之间建立适当的连接。

+0

您是否已经设置你的模型和关系雄辩? – sidneydobber

+0

你能指定你的模型应该如何与海誓山盟联系吗?如在演示文稿中可以有许多布局,布局可以有很多位置等。 – sidneydobber

回答

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列应该是唯一键。所以presetation 101将不得不像行:

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

我想要能够查询演示文稿,并在该对象内,能够循环或提取每个资产的适当位置。 – dcolumbus

+0

啊,你在使用“位置”就像我在我的答案中使用“顺序”。我会更新一下... – bitfiddler

+0

那么你的例子渲染'布局'没用?我绝不意味着我最初的想法是正确的路要走......我只需要创建这种关系,以便它具有可扩展性。 – dcolumbus

0

回答正在进行

*还有很多工作要做,但需要从作者更多的输入

你打算结构对我来说还不是很清楚,但是当你首先设置你的实现时,你会在开始考虑数据库列之前有一种草图。

如果您使用的雄辩会是这个样子:

用户

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'); 
    } 

} 
+0

是的,我只是不知道我最初的想法是否是最好的方法。我使用雄辩,所以谢谢你去那个角度。另一个问题是,目前,我的资产都在各自的表格中(图片,视频,文本)。 – dcolumbus

+0

我不认为这是一个问题。如果你知道你想要走哪条路,就留言吧。我喜欢做这种东西! :) – sidneydobber

+0

我想我想让我的资产保存在各自的表格(文本,图片,视频)中。但我不认为我想为布局和布局额外的表格和模型而烦恼......这看起来非常多余,我甚至不知道“职位”表中的信息是什么。因此,如果以某种方式连接资产和他们在演示文稿中的位置(无论是否具有布局),我不确定。思考? – dcolumbus