Created
June 20, 2012 06:36
-
-
Save sdepold/2958440 to your computer and use it in GitHub Desktop.
"virtual fields" in sequelize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize') | |
var sequelize = new Sequelize('sequelize_test', 'root') | |
var Person = sequelize.define('Person', { | |
firstName: Sequelize.STRING, | |
lastName: Sequelize.STRING | |
}, { | |
instanceMethods: { | |
getFullName: function() { | |
return [this.firstName, this.lastName].join(' ') | |
} | |
} | |
}) | |
sequelize.sync().success(function() { | |
Person | |
.create({ firstName: 'Sascha', lastName: 'Depold' }) | |
.success(function(sdepold){ console.log(sdepold.getFullName()) }) | |
}) |
would u like to create an example gist and add a link to it to the pull request? I finally understood what that ticket is about :) I like the idea
Am Mittwoch, 20. Juni 2012 um 20:29 schrieb Pranil Dasika:
… Hello Sascha!
The use case I am referring to is the one mentioned in https://github.com/1602/express-on-railway/issues/77 . While creating the User we should be able to set the password field even though it is not part of the schema whereas the salt and hash would be part of the schema.
For e.g the schema could be defined as
sequelize.define('Users', {
email: DataTypes.STRING,
salt: DataTypes.STRING,
hash : DataTypes.STRING
})
Whereas it can be created as:
User.create(email: ***@***.*** ***@***.***)' ,
password: userInfo.password)
The setter method abstracts out the population of salt and hash fields and the getter method should return the original password.
There seems to be a pull request which addresses this: https://github.com/sdepold/sequelize/pull/70.
- Thanks
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2958440
thanks!
Am Donnerstag, 21. Juni 2012 um 11:00 schrieb Pranil Dasika:
… Hello Sascha!
Done. Added https://gist.github.com/2964211 to the pull request.
Thanks,
Pranil
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2958440
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Sascha!
The use case I am referring to is the one mentioned in https://github.com/1602/express-on-railway/issues/77 . While creating the User we should be able to set the password field even though it is not part of the schema whereas the salt and hash would be part of the schema.
For e.g the schema could be defined as
sequelize.define('Users', {
email: DataTypes.STRING,
salt: DataTypes.STRING,
hash : DataTypes.STRING
})
Whereas it can be created as:
User.create(email: '[email protected]' ,
password: userInfo.password)
The setter method abstracts out the population of salt and hash fields and the getter method should return the original password.
There seems to be a pull request which addresses this: https://github.com/sdepold/sequelize/pull/70.