| 120 | } |
| 121 | |
| 122 | _initValues(values, options) { |
| 123 | let defaults; |
| 124 | let key; |
| 125 | |
| 126 | values = { ...values }; |
| 127 | |
| 128 | if (options.isNewRecord) { |
| 129 | defaults = {}; |
| 130 | |
| 131 | if (this.constructor._hasDefaultValues) { |
| 132 | defaults = _.mapValues(this.constructor._defaultValues, valueFn => { |
| 133 | const value = valueFn(); |
| 134 | return value && value instanceof Utils.SequelizeMethod ? value : _.cloneDeep(value); |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | // set id to null if not passed as value, a newly created dao has no id |
| 139 | // removing this breaks bulkCreate |
| 140 | // do after default values since it might have UUID as a default value |
| 141 | if (this.constructor.primaryKeyAttributes.length) { |
| 142 | this.constructor.primaryKeyAttributes.forEach(primaryKeyAttribute => { |
| 143 | if (!Object.prototype.hasOwnProperty.call(defaults, primaryKeyAttribute)) { |
| 144 | defaults[primaryKeyAttribute] = null; |
| 145 | } |
| 146 | }); |
| 147 | } |
| 148 | |
| 149 | if (this.constructor._timestampAttributes.createdAt && defaults[this.constructor._timestampAttributes.createdAt]) { |
| 150 | this.dataValues[this.constructor._timestampAttributes.createdAt] = Utils.toDefaultValue(defaults[this.constructor._timestampAttributes.createdAt], this.sequelize.options.dialect); |
| 151 | delete defaults[this.constructor._timestampAttributes.createdAt]; |
| 152 | } |
| 153 | |
| 154 | if (this.constructor._timestampAttributes.updatedAt && defaults[this.constructor._timestampAttributes.updatedAt]) { |
| 155 | this.dataValues[this.constructor._timestampAttributes.updatedAt] = Utils.toDefaultValue(defaults[this.constructor._timestampAttributes.updatedAt], this.sequelize.options.dialect); |
| 156 | delete defaults[this.constructor._timestampAttributes.updatedAt]; |
| 157 | } |
| 158 | |
| 159 | if (this.constructor._timestampAttributes.deletedAt && defaults[this.constructor._timestampAttributes.deletedAt]) { |
| 160 | this.dataValues[this.constructor._timestampAttributes.deletedAt] = Utils.toDefaultValue(defaults[this.constructor._timestampAttributes.deletedAt], this.sequelize.options.dialect); |
| 161 | delete defaults[this.constructor._timestampAttributes.deletedAt]; |
| 162 | } |
| 163 | |
| 164 | for (key in defaults) { |
| 165 | if (values[key] === undefined) { |
| 166 | this.set(key, Utils.toDefaultValue(defaults[key], this.sequelize.options.dialect), { raw: true }); |
| 167 | delete values[key]; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | this.set(values, options); |
| 173 | } |
| 174 | |
| 175 | // validateIncludedElements should have been called before this method |
| 176 | static _paranoidClause(model, options = {}) { |