Open mhuggins opened 10 years ago
After digging around a bit more, this doesn't look doable. However, I can't determine a way to approach this with the existing node-orm without having redundant validation in a separate location, at which point I would rather just use a different ORM. If you are open to a pull request, I think one of the following approaches would be suitable to my needs:
virtual: true
to allow properties to be included without being saved,mapTo
property option and interpret mapTo: null
. (I prefer this over the first approach since it doesn't allow confusing combinations like mapTo: 'first_name', virtual: true
),implement some kind of custom fields definition in the define
function's options, which are taken into account when creating an instance & can also be used in validations, etc.:
db.define('user', {
id : { type: 'serial', key: true },
email : { type: 'text', required: true, unique: true },
encryptedPassword : { type: 'text', required: true, mapsTo: 'encrypted_password' }
}, {
customProperties: {
password : { type: 'text' },
passwordConfirmation : { type: 'text' }
},
// validations, hooks, etc.
}
Thoughts?
I'm going to switch to Sequelize so I can keep moving forward, thanks anyway.
Hi there!
I'm trying to use to build out a user model that has an
encryptedPassword
property attached to a DB field, while trying to add custompassword
andpasswordConfirmation
properties (essentially virtual attributes that don't get saved), which are used to generate a password hash. Here's a sample of what I mean.Then when creating a user:
After digging through the code, I see that this doesn't work as I'd hoped, and my custom properties (password/passwordConfirmation) don't get assigned through the
create
call, instead just getting stripped from the object. I'm wondering if this is something that could/should be added as a feature, or if there's another/better way of approaching this that I'm not familiar with. I couldn't find anything in the docs or elsewhere.