From f84d7c7c7dea3719cc91252f24e3408484b12965 Mon Sep 17 00:00:00 2001 From: Mohit Sud Date: Tue, 22 Sep 2020 22:23:48 -0700 Subject: [PATCH] Implemented hasMany (many to many) relationships in RealtimeDatabase --- addon/serializers/realtime-database.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addon/serializers/realtime-database.ts b/addon/serializers/realtime-database.ts index 75dd01af..48747551 100644 --- a/addon/serializers/realtime-database.ts +++ b/addon/serializers/realtime-database.ts @@ -96,5 +96,18 @@ const normalizeEmbedded = (store: DS.Store, attribute: any, relationship: any, i } } -const normalizeHasMany = (_store: DS.Store, _attribute: any, _relationship: any, _included: any[]) => - ({ links: { related: 'emberfire' } }) \ No newline at end of file +const normalizeHasMany = (_store, _attribute, _relationship, _included) => { + //taken from firestore + var data = []; + if(_attribute) { + var idsForRelationships = Object.keys(_attribute); + data = idsForRelationships.map( (key) => ({id: key, type: _relationship.type}) ) + } + + if (data.length > 0) { + return { data }; + } else { + data = []; + return { data }; + } +}