Counting length of a hasMany relationship in v3
oskarrough opened this issue · comments
Hi, in v2 you could do
// models/post.js
this.hasMany('comments').ids() // [1,2,3]
to get the length of a relationship from the keys without having to fetch them. In vEmberfire v3 it returns an empty array []
, even when the relationship is loaded.
Is there an equivalent or smarter way in Emberfire v3? Thanks!
+1
I have the same issue here: #586
This would fetch the data, which is unoptimal. I'd suggest this solution: https://github.com/firebase/functions-samples/tree/master/child-count
Increment/decrement a child count on the server-side on child addition/deletion with Cloud Functions.
@jamesdaniels but it doesn't fetch the data in the v2 version? That was the neat part. No need for any extra cloud function per relationship. Appreciate the suggestion anyway!
That was because in v2 the realtionship's ids were embedded on the document. Which led to many many other problems :P
The child count Cloud Function is the correct path, after all v2 was created before we had Cloud Functions, and our new Distributed Counter Extension handles this same problem at scale (> 1 counter increment / second sustained).