{"action":"created","issue":{"url":"https://api.github.com/repos/jagi/meteor-astronomy-slug-behavior/issues/5","labels_url":"https://api.github.com/repos/jagi/meteor-astronomy-slug-behavior/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/jagi/meteor-astronomy-slug-behavior/issues/5/comments","events_url":"https://api.github.com/repos/jagi/meteor-astronomy-slug-behavior/issues/5/events","html_url":"https://github.com/jagi/meteor-astronomy-slug-behavior/issues/5","id":116105005,"number":5,"title":"slug is not being generated when instance is created","user":{"login":"zvictor","id":181076,"avatar_url":"https://avatars.githubusercontent.com/u/181076?v=3","gravatar_id":"","url":"https://api.github.com/users/zvictor","html_url":"https://github.com/zvictor","followers_url":"https://api.github.com/users/zvictor/followers","following_url":"https://api.github.com/users/zvictor/following{/other_user}","gists_url":"https://api.github.com/users/zvictor/gists{/gist_id}","starred_url":"https://api.github.com/users/zvictor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zvictor/subscriptions","organizations_url":"https://api.github.com/users/zvictor/orgs","repos_url":"https://api.github.com/users/zvictor/repos","events_url":"https://api.github.com/users/zvictor/events{/privacy}","received_events_url":"https://api.github.com/users/zvictor/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-10T13:22:09Z","updated_at":"2015-11-10T16:02:05Z","closed_at":"2015-11-10T16:02:05Z","body":"# Problem\r\nI observed that when I run `new MyClass({title: 'my title'}).save()` the value of the field `slug` is saved as `null`.\r\n\r\nThe line `Class.getBehavior('slug').generateSlug(doc)` never runs.\r\n\r\n# Scenario\r\n\r\nI have the following code added in a given `MyClass` definition:\r\n\r\n```js\r\n// ...\r\n  fields: {\r\n      title: 'string'\r\n  },\r\n  behaviors: {\r\n    slug: {\r\n      fieldName: 'title',\r\n      slugFieldName: 'slug',\r\n      canUpdate: true,\r\n      unique: true,\r\n      separator: '-'\r\n    }\r\n  }\r\n```\r\n\r\nNotice that there is no definition of the field `slug` in my class, it is defined by the behavior.\r\n\r\n# Debugging\r\n\r\n1. The default value for the field is `null`. **Setting it as the `generateSlug` method could be a solution.**\r\n<img width=\"526\" alt=\"screen shot 2015-11-10 at 14 00 54\" src=\"https://cloud.githubusercontent.com/assets/181076/11062958/8955b8aa-87b3-11e5-98a9-b5a3d5314585.png\">\r\n\r\n2. When we run our `beforeSave` event listener, the value for the slug field is `null`. We then check for modifications in the field before we generate a new slug.\r\n<img width=\"472\" alt=\"screen shot 2015-11-10 at 14 07 47\" src=\"https://cloud.githubusercontent.com/assets/181076/11063094/7d610d6e-87b4-11e5-90bb-3d478aa78d98.png\">\r\n\r\n3. As there has not been any modifications to our data, **the function returns prematurely and no slug is generated**. "},"comment":{"url":"https://api.github.com/repos/jagi/meteor-astronomy-slug-behavior/issues/comments/155464964","html_url":"https://github.com/jagi/meteor-astronomy-slug-behavior/issues/5#issuecomment-155464964","issue_url":"https://api.github.com/repos/jagi/meteor-astronomy-slug-behavior/issues/5","id":155464964,"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":"2015-11-10T16:02:05Z","updated_at":"2015-11-10T16:02:05Z","body":"```js\r\nvar doc = MyClass();\r\ndoc.set({title: 'my title'});\r\ndoc.save();\r\n```\r\n\r\nWill solve your problem"}}