bookshelf icon indicating copy to clipboard operation
bookshelf copied to clipboard

Count on relation should work for belongsToMany relations.

Open yoshiwarab opened this issue 5 years ago • 3 comments

  • Related Issues: #1075

Introduction

When calling count on a relationship collection, if the relation is belongsToMany, count returns the count of the entire table instead of just the related entries. The belongsToMany case did not seem to be handled at all previously in sync.js.

Motivation

Describe the problems that this proposal seeks to address and why it's important. If it's completely new functionality explain why this new functionality is necessary.

Proposed solution

Describe your solution to the problem. If possible provide examples and describe how they work. Show why your solution is better than what's currently available: is it cleaner, safer, or more efficient?

Current PR Issues

Are there any known issues in this Pull Request? This will help others understand if more work will be needed.

Alternatives considered

Describe any alternative approaches to addressing the same problem that you have thought about, and why you chose this approach instead.

yoshiwarab avatar Dec 09 '20 01:12 yoshiwarab

Will do!

yoshiwarab avatar Dec 09 '20 19:12 yoshiwarab

@ricardograca, fixed the linter issue and added a test that seems to be passing. Not sure why the build is failing, could you take a look when you get the chance?

yoshiwarab avatar Dec 11 '20 01:12 yoshiwarab

Thanks! One of the jobs just hanged and timed out without any errors at the end, so I just restarted it. I'll check the code later.

ricardograca avatar Dec 11 '20 16:12 ricardograca