millas 0.2.34 → 0.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/orm/fields/index.js
CHANGED
|
@@ -21,6 +21,7 @@ class FieldDefinition {
|
|
|
21
21
|
this._fkOnDelete = options._fkOnDelete ?? 'CASCADE';
|
|
22
22
|
this._fkRelatedName = options._fkRelatedName ?? null;
|
|
23
23
|
this._m2mThrough = options._m2mThrough ?? null;
|
|
24
|
+
this.columnName = options.columnName || options.column_name || null;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
nullable_(val = true) {
|
|
@@ -184,6 +185,7 @@ const fields = {
|
|
|
184
185
|
_fkToField: opts.toField ?? 'id',
|
|
185
186
|
_fkOnDelete: opts.onDelete ?? 'CASCADE',
|
|
186
187
|
_fkRelatedName: opts.relatedName ?? null,
|
|
188
|
+
columnName: opts.columnName || opts.column_name || null,
|
|
187
189
|
});
|
|
188
190
|
},
|
|
189
191
|
|
|
@@ -206,6 +208,7 @@ const fields = {
|
|
|
206
208
|
_fkToField: opts.toField ?? 'id',
|
|
207
209
|
_fkOnDelete: opts.onDelete ?? 'CASCADE',
|
|
208
210
|
_fkRelatedName: opts.relatedName ?? null,
|
|
211
|
+
columnName: opts.columnName || opts.column_name || null,
|
|
209
212
|
});
|
|
210
213
|
},
|
|
211
214
|
|
package/src/orm/model/Model.js
CHANGED
|
@@ -1005,7 +1005,8 @@ class Model {
|
|
|
1005
1005
|
const fieldDefs = this.getFields();
|
|
1006
1006
|
const result = {};
|
|
1007
1007
|
for (const [key, val] of Object.entries(data)) {
|
|
1008
|
-
|
|
1008
|
+
const dbColumn = fieldDefs[key]?.columnName || key;
|
|
1009
|
+
result[dbColumn] = this._serializeValue(val, fieldDefs[key]?.type);
|
|
1009
1010
|
}
|
|
1010
1011
|
return result;
|
|
1011
1012
|
}
|
|
@@ -420,12 +420,14 @@ class QueryBuilder {
|
|
|
420
420
|
async update(data) {
|
|
421
421
|
const F = require('./F');
|
|
422
422
|
const extra = this._model._updatedAtPayload?.() ?? {};
|
|
423
|
+
const fieldDefs = this._model.getFields();
|
|
423
424
|
const payload = {};
|
|
424
425
|
for (const [key, val] of Object.entries({ ...data, ...extra })) {
|
|
426
|
+
const dbColumn = fieldDefs[key]?.columnName || key;
|
|
425
427
|
if (val instanceof F) {
|
|
426
|
-
payload[
|
|
428
|
+
payload[dbColumn] = val.toKnex(this._query.client);
|
|
427
429
|
} else {
|
|
428
|
-
payload[
|
|
430
|
+
payload[dbColumn] = val;
|
|
429
431
|
}
|
|
430
432
|
}
|
|
431
433
|
return this._query.update(payload);
|