Hi folks,
I'm trying to generate some url 'slugs' for my website. It's based upon a single piece of user generated text.
Now, i have made my own slug method, so i'm not after some code for that.
What i'm wondering is where is the best place to determine if this slug is unique and then insert it because the slug field is a Unique Key Index.
Originally, i had a trigger on any insert (against the table) so when the data is entered, the slug is then determined. I had a function that checked for the number of records that contained the user's text (not the slug) and then generated the slug and added the record count + 1 to the end of the new slug.
eg.
5 records are found in the table with the same User generated content. the slug for this now the slug-text with a 6 added to the end.
Flaws: if the user changes their text, the slug doesn't change.
Anyways, i'm wondering if other people have delt with this issue before and found any ways to fix it?