Proposed Feature
Adds a fixture-level flag to disable the user of setter methods. This is a necessary feature if your model's setter methods us instance methods other than simple this.setDataValue.
The new flag will be called ignoreSet or something like:
ignoreSetter
ignoreSetters
ignorePropertySetter
ignorePropertySetters
- Something else? Thoughts on a better name?
Usage
- model: User
ignoreSet: true
data:
email: foo@bar.com
Other Thoughts
Considered putting this under an options object as:
- model: User
options:
ignoreSet: true
data:
email: foo@bar.com
But so far there are no other sequelize-fixtures specific options (the options are pass-through options for sequelize build / create methods only.
Background
If you use property setters, this library attempts to feed values from fixtures into them in case there is some coercion or formatting, etc.
The Problem
This library calls the setters in a simulated way, without a real object instance.
Steps to reproduce
- Define a model with at least one
set method using any instance method inside (e.g. this.previous or anything except this.setDataValue).
Example:
const User = sequelize.define('User', {
id: {
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
email: {
type: DataTypes.STRING,
validate: {
isEmail: true
},
set: function set(val) {
if (this.previous('email')) {
throw new Error('Updating email is not allowed');
}
this.setDataValue('email', val);
}
}
});
Actual behavior
[TypeError: this.previous is not a function
Expected behavior: using defined instance methods should not fail
// caused by this:
Model.rawAttributes[k].set.call(Model, data[k]);
Proposed Feature
Adds a fixture-level flag to disable the user of setter methods. This is a necessary feature if your model's setter methods us instance methods other than simple
this.setDataValue.The new flag will be called
ignoreSetor something like:ignoreSetterignoreSettersignorePropertySetterignorePropertySettersUsage
Other Thoughts
Considered putting this under an
optionsobject as:But so far there are no other sequelize-fixtures specific options (the options are pass-through options for sequelize
build/createmethods only.Background
If you use property setters, this library attempts to feed values from fixtures into them in case there is some coercion or formatting, etc.
The Problem
This library calls the setters in a simulated way, without a real object instance.
Steps to reproduce
setmethod using any instance method inside (e.g.this.previousor anything exceptthis.setDataValue).Example:
Actual behavior
Expected behavior: using defined instance methods should not fail