alphagov/govuk_content_models — pull request #102 by fatbusinessman (2013-11-15 10:12:47+00:00)
Title: Fix indexing for the `relatable_items` method.

Ok, there's a bunch of things I misunderstood here:

* Inequality checking isn't any better for the index than "not in" exclusion. There's nothing stopping us switching back to the `$nin` form for the `kind` and `state` filters, should we need to exclude multiple values.

* The name should always have gone first in the query, because we're sorting on it. Oops.

* Mongo indexes don't include the `_id` field unless you specifically include it. I had assumed the index would implicitly include the document's ID, but we need to add it explicitly for a covered query.

* Because `Artefact` has other types inheriting from it, Mongoid will automatically ask for a `_type` field in any artefact query and use that to determine which class to instantiate, so we need to include that in the index to cover the query. I didn't spot that.