Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
buildHasManyCollectionRef(store, snapshot, url, relationship) {
const db = this.firebase.firestore();
const cardinality = snapshot.type.determineRelationshipType(relationship, store);
let collectionRef;
if (cardinality === 'manyToOne') {
const inverse = snapshot.type.inverseFor(relationship.key, store);
const collectionName = buildCollectionName(snapshot.modelName);
const reference = db.collection(collectionName).doc(snapshot.id);
collectionRef = db.collection(url).where(inverse.name, '==', reference);
} else if (Object.prototype.hasOwnProperty.call(relationship.options, 'buildReference')) {
collectionRef = relationship.options.buildReference(db, snapshot.record);
} else {
collectionRef = buildRefFromPath(db, url);
}
return this.buildQuery(collectionRef, relationship.options, snapshot.record);
},
buildReference(db) {
return buildRefFromPath(db, urlNodes.join('/'));
},
},
serializeBelongsTo(snapshot, json, relationship) {
this._super(snapshot, json, relationship);
if (json[relationship.key]) {
const collectionName = buildCollectionName(relationship.type);
const docId = json[relationship.key];
const path = `${collectionName}/${docId}`;
json[relationship.key] = buildRefFromPath(this.firebase.firestore(), path);
}
},