Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL 5.5 Database design. Problem with friendly URLs approach
    primarykey
    data
    text
    <p>I have a maybe stupid question but I need to ask it :-)</p> <p>My Friendly URL (furl) database design approach is fairly summarized in the following diagram (<strong>InnoDB</strong> at <strong>MySQL 5.5</strong> used)</p> <p><img src="https://i.stack.imgur.com/8OYy2.png" alt="diagram"></p> <p>Each item will generate as many furls as languages available on the website. The furl_redirect table represents the controller path for each item. I show you an example:</p> <pre><code>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' </code></pre> <p>When you insert a new item, its furl_redirect and furls must be also inserted. The problem appears becouse of the (necessary) unique constraint in the furl table. As you see above, in order to get unique urls, I use the title of the item (it is not necessarily unique) + the id to create the unique url. That means the order of inserting rows should be as follow:</p> <pre><code>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) </code></pre> <p>I would like an <strong>elegant solution</strong> to this problem, but I can not get it!</p> <p>Is there a way of getting the <strong>next AutoIncrement value</strong> on an InnoDB Table?, and is it recommended to use it? Can you think of another way to ensure the <strong>uniqueness of the friendly urls</strong> that is independent of the items' id? Am I missing something crucial?</p> <p>Any solution is welcome!</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload