{"action":"created","issue":{"url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/494","repository_url":"https://api.github.com/repos/jagi/meteor-astronomy","labels_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/494/labels{/name}","comments_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/494/comments","events_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/494/events","html_url":"https://github.com/jagi/meteor-astronomy/issues/494","id":174561610,"number":494,"title":"Default values and optional flag","user":{"login":"jhuenges","id":7192165,"avatar_url":"https://avatars.githubusercontent.com/u/7192165?v=3","gravatar_id":"","url":"https://api.github.com/users/jhuenges","html_url":"https://github.com/jhuenges","followers_url":"https://api.github.com/users/jhuenges/followers","following_url":"https://api.github.com/users/jhuenges/following{/other_user}","gists_url":"https://api.github.com/users/jhuenges/gists{/gist_id}","starred_url":"https://api.github.com/users/jhuenges/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhuenges/subscriptions","organizations_url":"https://api.github.com/users/jhuenges/orgs","repos_url":"https://api.github.com/users/jhuenges/repos","events_url":"https://api.github.com/users/jhuenges/events{/privacy}","received_events_url":"https://api.github.com/users/jhuenges/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-01T15:58:12Z","updated_at":"2016-09-01T19:39:35Z","closed_at":"2016-09-01T19:30:35Z","body":"I have two classes\r\n```js\r\nexport default Class.create({\r\n  name: 'Person',\r\n  collection: Persons,\r\n  secured: false,\r\n  fields: {\r\n    ...\r\n   deathdate: {\r\n      type: CustomDate,\r\n      optional: true,\r\n      default() {\r\n        return new CustomDate();\r\n      }\r\n    },\r\n    ...\r\n  }\r\n```\r\nand \r\n\r\n```js\r\nexport default Class.create({\r\n  name: 'CustomDate',\r\n  fields: {\r\n    year: {\r\n      type: Number,\r\n      optional: false,\r\n      validators: [{\r\n        type: 'and',\r\n        param: [{\r\n          type: 'gt',\r\n          param: 1000\r\n        }, {\r\n          type: 'lt',\r\n          param: 9999\r\n        }]\r\n      }]\r\n    },\r\n    month: {\r\n      type: Number,\r\n      optional: true,\r\n      validators: [{\r\n        type: 'and',\r\n        param: [{\r\n          type: 'gt',\r\n          param: 0\r\n        }, {\r\n          type: 'lt',\r\n          param: 13\r\n        }]\r\n      }]\r\n    },\r\n    day: {\r\n      type: Number,\r\n      optional: true,\r\n      validators: [{\r\n        type: 'and',\r\n        param: [{\r\n          type: 'gt',\r\n          param: 0\r\n        }, {\r\n          type: 'lt',\r\n          param: 32\r\n        }]\r\n      }]\r\n    }\r\n  }\r\n});\r\n```\r\n\r\nWhen I create a new person, the person is not necessarily dead (who could have guessed that! :D). Thats why `deathdate` is an optional field. But when I try to validate the object, it throws an error because in `CustomDate` the `year` is not optional. Shouldnt the field `deathdate` be optional and therefore not throw the error if it is not used?"},"comment":{"url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/comments/244188842","html_url":"https://github.com/jagi/meteor-astronomy/issues/494#issuecomment-244188842","issue_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/494","id":244188842,"user":{"login":"jagi","id":1051229,"avatar_url":"https://avatars.githubusercontent.com/u/1051229?v=3","gravatar_id":"","url":"https://api.github.com/users/jagi","html_url":"https://github.com/jagi","followers_url":"https://api.github.com/users/jagi/followers","following_url":"https://api.github.com/users/jagi/following{/other_user}","gists_url":"https://api.github.com/users/jagi/gists{/gist_id}","starred_url":"https://api.github.com/users/jagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jagi/subscriptions","organizations_url":"https://api.github.com/users/jagi/orgs","repos_url":"https://api.github.com/users/jagi/repos","events_url":"https://api.github.com/users/jagi/events{/privacy}","received_events_url":"https://api.github.com/users/jagi/received_events","type":"User","site_admin":false},"created_at":"2016-09-01T19:39:35Z","updated_at":"2016-09-01T19:39:35Z","body":"So just don't provide default value for the `deathdate` field, it's not necessary. Or if you need to have year because it's required then you should provide year for every `CustomDate` document. It's just design problem, not framework problem."}}
{"actor":{"display_login":"jagi"}}