Skip to content

Commit 3512a9d

Browse files
committed
Support native arrays
1 parent 6c9a413 commit 3512a9d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"coverageThreshold": {
137137
"global": {
138138
"statements": 93,
139-
"branches": 82,
139+
"branches": 80,
140140
"functions": 98,
141141
"lines": 94
142142
}

src/graphql/transformer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ export default class Transformer {
4646
? context.getModel(singularize(relations.get(key)!.parent!.entity), true)
4747
: null;
4848
if (value instanceof Array) {
49-
// Iterate over all fields and transform them if value is an array
50-
const arrayModel = context.getModel(singularize(key));
51-
returnValue[key] = value.map(v => this.transformOutgoingData(arrayModel || model, v));
49+
// Either this is a hasMany field or a .attr() field which contains an array.
50+
const arrayModel = context.getModel(singularize(key), true);
51+
52+
if (arrayModel) {
53+
returnValue[key] = value.map(v => this.transformOutgoingData(arrayModel || model, v));
54+
} else {
55+
returnValue[key] = value;
56+
}
5257
} else if (typeof value === "object" && value.$id !== undefined) {
5358
if (!relatedModel) {
5459
relatedModel = context.getModel((value as ORMModel).$self().entity);

0 commit comments

Comments
 (0)