{"issue":{"created_at":"2011-12-11T07:41:09Z","state":"open","updated_at":"2011-12-11T08:52:21Z","comments":1,"user":{"gravatar_id":"2b7a125030f3d8b887bf5b061a8eb5f2","id":42518,"url":"https://api.github.com/users/cayasso","avatar_url":"https://secure.gravatar.com/avatar/2b7a125030f3d8b887bf5b061a8eb5f2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"cayasso"},"body":"How to avoid unwanted fields (not declared in schema) to be saved to my database?, for example, authenticity_token or password. \r\n\r\nAn another question: In previous version of railway when using mongoose I used to do define a virtual and a setter to save my password (instead of password, salt and hash was saved to my DB)\r\n\r\n<pre>\r\nUser.virtual('password')\r\n  .get(function(){\r\n      return this._password;\r\n  })\r\n  .set(function(password) {\r\n    this._password = password;      \r\n    var salt = this.salt = bcrypt.gen_salt_sync(10);\r\n    this.hash = bcrypt.encrypt_sync(password, salt);\r\n  });\r\n\r\n</pre>\r\n\r\nWhat would be the equivalent of doing so with the new way of defining schemas, I tried to use beforeCreate and beforeSave but those methods doesnt have access to the req.body.password from the form, so is there an easy way to do this in schema or I would need to force it in the Controller?.\r\n\r\nThanks!\r\n\r\nJB\r\n","assignee":null,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"id":2515080,"number":77,"labels":[],"title":"How to avoid unwanted feilds to be saved to database","html_url":"https://github.com/1602/express-on-railway/issues/77","closed_at":null,"url":"https://api.github.com/repos/1602/express-on-railway/issues/77","milestone":null},"action":"created","comment":{"created_at":"2011-12-11T08:52:21Z","updated_at":"2011-12-11T08:52:21Z","user":{"gravatar_id":"00bcc518cddfa8502e2e8e219f3cdfb1","id":184172,"url":"https://api.github.com/users/1602","avatar_url":"https://secure.gravatar.com/avatar/00bcc518cddfa8502e2e8e219f3cdfb1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"1602"},"body":"1. to avoid unwanted fields you shouldn't do any additional actions\r\n\r\n+    it('should save only schema-defined field in database', function (test) {\r\n+        Post.create({title: '1602', nonSchemaField: 'some value'}, function (err, post)\r\n+            test.ok(!post.nonSchemaField);\r\n+            post.a = 1;\r\n+            post.save(function () {\r\n+                test.ok(post.a);\r\n+                post.reload(function (err, psto) {\r\n+                    test.ok(!post.a);\r\n+                    test.done();\r\n+                });\r\n+            });\r\n+        });\r\n+    });\r\n\r\n2. nice feature, will add it to jugglingdb shortly, thanks!","id":3096176,"url":"https://api.github.com/repos/1602/express-on-railway/issues/comments/3096176"}}