alphagov/govuk_content_models — pull request #116 by JordanHatch (2014-02-06 12:21:34+00:00)
Title: Store tags for an artefact with their tag types

At the moment, associated tags for an artefact are stored as an array of strings, each representing the tag's ID. However, these tag IDs omit any information about the type of the tag. A typical artefact's `tag_id` field could look like this:
```
["business/setting-up","businesslink","oil-and-gas/fields-and-wells"]
```
In this example, each of the tags is actually a different type, but there's no context to indicate this in the data. Tag IDs only have to be unique across tags of the same type, so we could easily run into conflicts in the `tag_ids` field as we add more tags across many more types.

This pull request is the first step towards changing how we store tags for an artefact. In the future, I'd like to see a tags field which looks like this:
```
[{ tag_id: "business", tag_type: "section" }, { tag_id: "oil-and-gas", tag_type: "industry_sector" }]
```
The changes made by this branch modify the `Artefact` model so that, whenever tags are saved, they are also now saved to a new field, `tags`, in a structure that resembles the above example. I have also included a class method on the `Tag` model which finds the right tags when given an array of hashes like the one above.

The intention is to use these changes to start updating every artefact in production with the new tag structure, at which point we can start to phase out use of the existing `tag_ids` field.