Skip to content

Commit aec5690

Browse files
committed
Fix model detection
1 parent 3ef4f41 commit aec5690

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

dist/vuex-orm-graphql.esm.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27405,9 +27405,12 @@ var Transformer = /** @class */ (function () {
2740527405
var arrayModel_1 = context.getModel(inflection$1.singularize(key));
2740627406
returnValue[key] = value.map(function (v) { return _this.transformOutgoingData(arrayModel_1 || model, v); });
2740727407
}
27408-
else if (typeof value === 'object' && relatedModel) {
27408+
else if (typeof value === 'object' && value.$id !== undefined) {
27409+
if (!relatedModel) {
27410+
relatedModel = context.getModel(value.$self().entity);
27411+
}
2740927412
// Value is a record, transform that too
27410-
returnValue[key] = _this.transformOutgoingData(relatedModel || model, value);
27413+
returnValue[key] = _this.transformOutgoingData(relatedModel, value);
2741127414
}
2741227415
else {
2741327416
// In any other case just let the value be what ever it is

src/graphql/transformer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Data, Field } from '../support/interfaces';
22
import Model from '../orm/model';
3+
import { Model as ORMModel } from '@vuex-orm/core';
34
import Context from '../common/context';
45
import { downcaseFirstLetter } from '../support/utils';
56
import * as _ from 'lodash-es';
@@ -39,9 +40,13 @@ export default class Transformer {
3940
// Iterate over all fields and transform them if value is an array
4041
const arrayModel = context.getModel(inflection.singularize(key));
4142
returnValue[key] = value.map((v) => this.transformOutgoingData(arrayModel || model, v));
42-
} else if (typeof value === 'object' && relatedModel) {
43+
} else if (typeof value === 'object' && value.$id !== undefined) {
44+
if (!relatedModel) {
45+
relatedModel = context.getModel((value as ORMModel).$self().entity);
46+
}
47+
4348
// Value is a record, transform that too
44-
returnValue[key] = this.transformOutgoingData(relatedModel || model, value);
49+
returnValue[key] = this.transformOutgoingData(relatedModel, value);
4550
} else {
4651
// In any other case just let the value be what ever it is
4752
returnValue[key] = value;

0 commit comments

Comments
 (0)