pangea-server 1.0.53 → 1.0.54
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.
|
@@ -214,8 +214,7 @@ function convertWhereKeys(obj) {
|
|
|
214
214
|
const parts = inner.split('.');
|
|
215
215
|
if (parts.length >= 2) {
|
|
216
216
|
const last = parts.pop();
|
|
217
|
-
|
|
218
|
-
newKey = `$${[...parts, transformed].join('.')}$`;
|
|
217
|
+
newKey = `$${[...parts.map((part) => (0, pangea_helpers_1.camelToSnake)(part)), (0, pangea_helpers_1.camelToSnake)(last)].join('.')}$`;
|
|
219
218
|
}
|
|
220
219
|
}
|
|
221
220
|
newObj[newKey] = convertWhereKeys(value);
|
|
@@ -243,8 +242,8 @@ function getIncludeAndWhere(model, includeItems, config = {}, where, relDepth =
|
|
|
243
242
|
const relModel = rel.getModelFn();
|
|
244
243
|
includeOptions.push({
|
|
245
244
|
model: relModel,
|
|
246
|
-
as:
|
|
247
|
-
|
|
245
|
+
as: rel.as,
|
|
246
|
+
attributes: !config.withoutAttributes ? undefined : [],
|
|
248
247
|
required: rel.required,
|
|
249
248
|
paranoid: rel.paranoid,
|
|
250
249
|
...getIncludeAndWhere(relModel, nestedIncludeItems, config, relWhere, newRelDepth),
|
|
@@ -25,6 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.HasMany = exports.HasOne = exports.BelongsTo = void 0;
|
|
27
27
|
const seq = __importStar(require("sequelize-typescript"));
|
|
28
|
+
// helpers
|
|
29
|
+
const pangea_helpers_1 = require("pangea-helpers");
|
|
28
30
|
exports.BelongsTo = getRelation(seq.BelongsTo);
|
|
29
31
|
exports.HasOne = getRelation(seq.HasOne);
|
|
30
32
|
exports.HasMany = getRelation(seq.HasMany);
|
|
@@ -33,10 +35,11 @@ function getRelation(relationFn) {
|
|
|
33
35
|
return function (getModelFn, options = {}) {
|
|
34
36
|
return function (target, propertyName) {
|
|
35
37
|
const { foreignKey, ...relOptions } = options;
|
|
36
|
-
|
|
38
|
+
const as = (0, pangea_helpers_1.camelToSnake)(propertyName);
|
|
39
|
+
relationFn(getModelFn, { as, ...(foreignKey && { foreignKey }) })(target, propertyName);
|
|
37
40
|
const model = target.constructor;
|
|
38
41
|
const { eager = relationFn !== seq.HasMany, required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
|
|
39
|
-
model.AddRelation(propertyName, { getModelFn, eager, required, paranoid, joinDepth, ...restOptions });
|
|
42
|
+
model.AddRelation(propertyName, { as, getModelFn, eager, required, paranoid, joinDepth, ...restOptions });
|
|
40
43
|
};
|
|
41
44
|
};
|
|
42
45
|
}
|
|
@@ -35,6 +35,7 @@ function Table(tableName, options = {}) {
|
|
|
35
35
|
const allIndexes = [...tableIndexes, ...columnIndexes];
|
|
36
36
|
seq.Table({
|
|
37
37
|
tableName,
|
|
38
|
+
modelName: (0, pangea_helpers_1.camelToSnake)(target.name),
|
|
38
39
|
charset: 'utf8mb4',
|
|
39
40
|
collate: 'utf8mb4_general_ci',
|
|
40
41
|
underscored: true,
|