{"action":"opened","issue":{"url":"https://api.github.com/repos/keystonejs/keystone/issues/1007","labels_url":"https://api.github.com/repos/keystonejs/keystone/issues/1007/labels{/name}","comments_url":"https://api.github.com/repos/keystonejs/keystone/issues/1007/comments","events_url":"https://api.github.com/repos/keystonejs/keystone/issues/1007/events","html_url":"https://github.com/keystonejs/keystone/issues/1007","id":56793495,"number":1007,"title":"sortOrder not being initialized on item creation","user":{"login":"JohnnyEstilles","id":5514878,"avatar_url":"https://avatars.githubusercontent.com/u/5514878?v=3","gravatar_id":"","url":"https://api.github.com/users/JohnnyEstilles","html_url":"https://github.com/JohnnyEstilles","followers_url":"https://api.github.com/users/JohnnyEstilles/followers","following_url":"https://api.github.com/users/JohnnyEstilles/following{/other_user}","gists_url":"https://api.github.com/users/JohnnyEstilles/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnnyEstilles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnnyEstilles/subscriptions","organizations_url":"https://api.github.com/users/JohnnyEstilles/orgs","repos_url":"https://api.github.com/users/JohnnyEstilles/repos","events_url":"https://api.github.com/users/JohnnyEstilles/events{/privacy}","received_events_url":"https://api.github.com/users/JohnnyEstilles/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/keystonejs/keystone/labels/bug","name":"bug","color":"eb3d31"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-06T10:10:28Z","updated_at":"2015-02-06T10:10:28Z","closed_at":null,"body":"After [this commit](https://github.com/keystonejs/keystone/commit/8137c756656aaafadcba083a645858b66e00f183) (alt. implementation of #634, sortOrder type detection fix), `sortOrder` is no longer being initialized when an item is created.\r\n\r\nThe original code (below) tested the type of the `sortOrder` value, which is `undefined` before `sortOrder` is set, and `number` after it is.\r\n\r\n```js\r\nif (typeof this.sortOrder === 'number') {\r\n    return next();\r\n}\r\n```\r\n\r\nThe current code tests the type of the schema field type, which is always `mongoose.Schema.Types.Number` regardless of whether `sortOrder` is initialized or not. This is causing `sortOrder` not to be initialed upon creation.\r\n\r\n```js\r\nvar sortOrderType = this.schema.path('sortOrder');\r\nif (typeof sortOrderType !== 'undefined' && sortOrderType instanceof keystone.mongoose.Schema.Types.Number) {\r\n    return next();\r\n}\r\n```\r\n\r\nI propose we rollback this commit."}}