Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counting length of a hasMany relationship in v3 #587

Closed
oskarrough opened this issue Jul 19, 2019 · 4 comments
Closed

Counting length of a hasMany relationship in v3 #587

oskarrough opened this issue Jul 19, 2019 · 4 comments

Comments

@oskarrough
Copy link
Contributor

oskarrough commented Jul 19, 2019

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!

@charlesfries
Copy link

+1

I have the same issue here: #586

@jamesdaniels
Copy link
Contributor

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.

@oskarrough
Copy link
Contributor Author

@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!

@jamesdaniels
Copy link
Contributor

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants