views:

56

answers:

1

Is there an efficient way for a system to update tags for an item when presented side-by-side in a text box, similar to StackOverflow?

In my web app, individual items have tags and I am using a link table between a tags table and the items table to keep some normality.

Database schema are discussed here: http://stackoverflow.com/questions/172648/is-there-an-agreed-ideal-schema-for-tagging and here: http://stackoverflow.com/questions/373126/how-to-design-a-database-schema-to-support-tagging-with-categories

On every modification of the item, it would be easy to delete all the tags associated with the item, then re-add them to the database depending on the contents of the text box (tags separated by spaces).

However, that could mean 2/3 database calls even when the user has not made any changes.

I also considered not allowing modification of tags at all. On edit, I could present the user with a small cross by each tag, allowing them to delete the item via an AJAX call.

This solution though would not facilitate the user in circumstances such as amending a spelling error in an individual tag.

A: 

Thinking it through again, I suppose I will have a function which creates the tag string for display on the update form.

If, on update, I were to call that function again, and compare the string, at least I'd be able to filter out where the tags have not been changed at all with a single db call.

Then, only if the tags are different, I could do the update.

Could be quite efficient?

Jon Winstanley