Created
July 22, 2013 12:59
-
-
Save rodurma/6053651 to your computer and use it in GitHub Desktop.
Criar uma slug com o id do próprio registro no banco de dados.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DELIMITER $$ | |
| CREATE TRIGGER `create_slug` BEFORE INSERT | |
| ON `slugs` | |
| FOR EACH ROW | |
| BEGIN | |
| SET new.id = (SELECT MAX(id) FROM slugs) + 1; | |
| SET new.slug = CONCAT(new.slug, "-", new.id); | |
| END$$ | |
| DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment