From 4f77b2d5ea08685230ec60b5a3ddd2b3d3a7ec6c Mon Sep 17 00:00:00 2001 From: Ilya Radchenko Date: Thu, 7 Oct 2021 14:22:00 -0400 Subject: [PATCH] fix: modelName undefined when serializing fragment and fragment array (#407) * fix: modelName undefined when serializing fragment Resolves https://github.com/adopted-ember-addons/ember-data-model-fragments/issues/406 * fix: alternative model name for fragment array --- addon/transforms/fragment-array.js | 2 +- addon/transforms/fragment.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/transforms/fragment-array.js b/addon/transforms/fragment-array.js index 56b1fc3e..c7cd25dd 100644 --- a/addon/transforms/fragment-array.js +++ b/addon/transforms/fragment-array.js @@ -31,7 +31,7 @@ const FragmentArrayTransform = FragmentTransform.extend({ let store = this.store; return snapshots.map(snapshot => { - let serializer = store.serializerFor(snapshot.modelName); + let serializer = store.serializerFor(snapshot.modelName || snapshot.constructor.modelName); return serializer.serialize(snapshot); }); } diff --git a/addon/transforms/fragment.js b/addon/transforms/fragment.js index d62dfc59..8b080a73 100644 --- a/addon/transforms/fragment.js +++ b/addon/transforms/fragment.js @@ -35,7 +35,7 @@ const FragmentTransform = Transform.extend({ } let store = this.store; - let serializer = store.serializerFor(snapshot.modelName); + let serializer = store.serializerFor(snapshot.modelName || snapshot.constructor.modelName); return serializer.serialize(snapshot); },