{"action":"created","issue":{"url":"https://api.github.com/repos/js-data/js-data/issues/90","labels_url":"https://api.github.com/repos/js-data/js-data/issues/90/labels{/name}","comments_url":"https://api.github.com/repos/js-data/js-data/issues/90/comments","events_url":"https://api.github.com/repos/js-data/js-data/issues/90/events","html_url":"https://github.com/js-data/js-data/issues/90","id":64233590,"number":90,"title":"Default value for defined schema","user":{"login":"facultymatt","id":1406258,"avatar_url":"https://avatars.githubusercontent.com/u/1406258?v=3","gravatar_id":"","url":"https://api.github.com/users/facultymatt","html_url":"https://github.com/facultymatt","followers_url":"https://api.github.com/users/facultymatt/followers","following_url":"https://api.github.com/users/facultymatt/following{/other_user}","gists_url":"https://api.github.com/users/facultymatt/gists{/gist_id}","starred_url":"https://api.github.com/users/facultymatt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facultymatt/subscriptions","organizations_url":"https://api.github.com/users/facultymatt/orgs","repos_url":"https://api.github.com/users/facultymatt/repos","events_url":"https://api.github.com/users/facultymatt/events{/privacy}","received_events_url":"https://api.github.com/users/facultymatt/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-25T10:07:11Z","updated_at":"2015-03-25T17:05:38Z","closed_at":"2015-03-25T14:19:21Z","body":"Is if possible to set a default value when defining schema? For example:\r\n\r\n```\r\nvar Order = DS.defineResource({\r\n  name: 'order',\r\n  endpoint: 'orders',\r\n  idAttribute: '_id',\r\n  schema: {\r\n    status: {\r\n      type: 'string',\r\n      'default': 'NEW'\r\n    }\r\n  }\r\n});\r\n\r\nvar order = Order.create({});\r\n\r\nexpect(order.status).toEqual('NEW) // true\r\n```\r\n\r\nI see the schema library supports defaults via `setDefaults` but was not able to get it working in the content of defining a resource. "},"comment":{"url":"https://api.github.com/repos/js-data/js-data/issues/comments/86123378","html_url":"https://github.com/js-data/js-data/issues/90#issuecomment-86123378","issue_url":"https://api.github.com/repos/js-data/js-data/issues/90","id":86123378,"user":{"login":"jmdobry","id":1213510,"avatar_url":"https://avatars.githubusercontent.com/u/1213510?v=3","gravatar_id":"","url":"https://api.github.com/users/jmdobry","html_url":"https://github.com/jmdobry","followers_url":"https://api.github.com/users/jmdobry/followers","following_url":"https://api.github.com/users/jmdobry/following{/other_user}","gists_url":"https://api.github.com/users/jmdobry/gists{/gist_id}","starred_url":"https://api.github.com/users/jmdobry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmdobry/subscriptions","organizations_url":"https://api.github.com/users/jmdobry/orgs","repos_url":"https://api.github.com/users/jmdobry/repos","events_url":"https://api.github.com/users/jmdobry/events{/privacy}","received_events_url":"https://api.github.com/users/jmdobry/received_events","type":"User","site_admin":false},"created_at":"2015-03-25T17:05:38Z","updated_at":"2015-03-25T17:05:38Z","body":"So `resource`, while when you log it to the console it prints `Options ...`, it is actually the `options` variable wrapped in a constructor function that uses the resource definition as its prototype, so thanks to prototypal inheritance, it _is_ the resource in essence. You can explore [this line](https://github.com/js-data/js-data/blob/master/src/datastore/sync_methods/index.js#L123) to see that this is true.\r\n\r\nI will agree however, that I am passing the wrong second argument to `afterCreateInstance`. Instead of passing `attrs` I should be passing `item`, which is what is ultimately returned by the `createInstance` method. That right there is the bug, and [here](https://github.com/js-data/js-data/issues/91) is the issue for it.\r\n\r\nUntil I fix this bug, you'll just want to add defaults to items somewhere else, perhaps in the `afterInject` hook."}}