count queries limited
jean1880 opened this issue · 3 comments
When creating queries for count, they do not allow the same complex, nested queries that find allows, such as relational database queries. Count queries should be able to perform the same queries as a find statement, simply returning the count instead of the data. Currently when passing in a nested table, the query tries to query the column of the nested table from the parent table, without joining the tables first.
We haven't settled on a syntax within waterline to count associated records, though there is a conversation about this at https://github.com/balderdashy/waterline/issues/811. But yes, something like what you're describing is desirable once waterline officially supports counting associated records. There's also the problem of keeping the count query optimized when possible. Related to #65
Thanks for posting, @jean1880. I'm a repo bot-- nice to meet you!
It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:
- review our contribution guide to make sure this submission meets our criteria (only verified bugs with documented features, please; no questions, commentary, or bug reports about undocumented features or unofficial plugins)
- create a new issue with the latest information, including updated version details with error messages, failing tests, and a link back to the original issue. This allows GitHub to automatically create a back-reference for future visitors arriving from search engines.
Thanks so much for your help!
I'd like to reiterate on this.
Let's consider a (very artificial) example - two entities User and Address (User must have one Address).
I can do this:
User.find({
name: {contains: "a"},
address: {
street: {contains: "b"}
}
});
however this throws:
User.count({
name: {contains: "a"},
address: {
street: {contains: "b"}
}
});
It's because count (in contrast to find) will not add needed joins.
Note that I'm not interested in counting users nor his addresses. I merely want to how e.g. many users live in certain street.
Currently I know no way to do it in waterline, except for doing find and getting length of the resulting array (which is unacceptable).