Skip to content

Commit df95caa

Browse files
waltherjjbravo-kernel
authored andcommitted
fix: arrays not working properly (#23)
* fix: correct call signature for type-mapper.map fnc * add tests for datatypes ARRAY and VIRTUAL * linting
1 parent 9641bdc commit df95caa

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/type-mapper.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ class TypeMapper {
5555
result = {
5656
...ARRAY,
5757
// Sequelize requires attribute.type to be defined for ARRAYs
58-
items: this.map({ type: properties.type.type, allowNull: false }),
58+
items: this.map(
59+
attributeName,
60+
{ type: properties.type.type, allowNull: false },
61+
strategy,
62+
),
5963
};
6064
break;
6165
}
@@ -323,7 +327,11 @@ class TypeMapper {
323327

324328
case 'VIRTUAL': {
325329
// Use result for the return type (if defined)
326-
result = this.map({ ...properties, type: properties.type && properties.type.returnType });
330+
result = this.map(
331+
attributeName,
332+
{ ...properties, type: properties.type && properties.type.returnType },
333+
strategy,
334+
);
327335
break;
328336
}
329337

test/models/user.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ module.exports = sequelize => {
9797
};
9898
}
9999

100+
if (supportedDataType('ARRAY')) {
101+
Model.rawAttributes.ARRAY = {
102+
type: DataTypes.ARRAY(DataTypes.INTEGER),
103+
};
104+
}
105+
106+
if (supportedDataType('VIRTUAL')) {
107+
Model.rawAttributes.VIRTUAL = {
108+
type: DataTypes.VIRTUAL(DataTypes.BOOLEAN),
109+
get: () => true,
110+
};
111+
112+
Model.rawAttributes.VIRTUAL_DEPENDENCY = {
113+
type: new DataTypes.VIRTUAL(DataTypes.INTEGER, ['id']),
114+
get() {
115+
return this.get('id');
116+
},
117+
};
118+
}
119+
100120
// --------------------------------------------------------------------------
101121
// Custom options (as specified through `jsonSchema`) starting below.
102122
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)