Comments (2)
has_children? does 'self.children.exists?({})'. It might be better to use 'children.any?'. Can you see if this helps by overriding the method in your model?
from ancestry.
Looks like children.any? uses a count(*) query instead of selecting the first child. Ideally you could do something like this:
Model.includes(:children).roots
Then you would just have 2 queries, one for the original query and one to fetch children instead of N+1 queries.
from ancestry.
Related Issues (20)
- STI does not work with counter cache HOT 12
- Последовательное нахождение... HOT 6
- Heterogenous FK column / multiple ancestries on same model HOT 2
- Documentation on text_pattern_ops. HOT 1
- Limiting Depth Problem HOT 2
- implement tree_view from the arrange method HOT 3
- Adding a "\ HOT 1
- Adding a "/" at the end can reduce the amount of "OR" queries HOT 4
- "parent" does not work if the primary key is not :id HOT 3
- Similar package golang? HOT 3
- New Published Gem HOT 1
- Scope like descendants, but includes self too? HOT 2
- find and fix corrupted children counts HOT 5
- `descendants_count` counter cache? HOT 4
- Should implement or document double ancestry (father+mother) HOT 1
- Multi-tenant with multiple roots issue calling siblings HOT 5
- Rails 7 error if remove children deleted all path HOT 3
- Design and buid FTW Newsletter Landing Page
- anyone could give clarity to the readme? HOT 6
- Multiple root nodes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ancestry.