【发布时间】:2011-07-12 08:09:18
【问题描述】:
我有一个可能很愚蠢的问题,但我需要问它:-)
My Friendly URL (furl) 数据库设计方法在下图中得到了相当的总结(InnoDB 在 MySQL 5.5 使用过)
每个项目将生成与网站上可用的语言一样多的毛皮。 furl_redirect 表表示每个项目的控制器路径。我给你举个例子:
item.id = 1000
item.title = 'Example title'
furl_redirect = 'item/1000'
furl.url = 'en/example-title-1000'
furl.url = 'es/example-title-1000'
furl.url = 'it/example-title-1000'
当你插入一个新项目时,它的 furl_redirect 和 furls 也必须被插入。问题的出现是由于 furl 表中的(必要的)唯一约束。正如您在上面看到的,为了获得唯一的 url,我使用项目的标题(不一定是唯一的)+ id 来创建唯一的 url。这意味着插入行的顺序应该如下:
1. Insert item -- (and get the id of the new item inserted) ERROR!! furl_redirect_id must not be null!!
2. Insert furl_redirect -- (need the item id to create de path)
3. Insert furl -- (need the item id to create de url)
我想要一个优雅的解决方案来解决这个问题,但我无法得到它!
有没有办法在 InnoDB 表上获取 下一个 AutoIncrement 值?是否推荐使用它? 你能想出另一种方法来确保友好网址的唯一性独立于项目的ID吗?我错过了什么重要的东西吗?
欢迎任何解决方案!
谢谢!
【问题讨论】:
标签: mysql database-design insert relational-database friendly-url