Closed plopidou closed 2 years ago
This looks like an issue that may be fixed by https://github.com/dimagi/django-cte/pull/46. Your example may be a good starting point to create a test, which is needed before that PR can be merged.
Thank you.
Just to clarify, this is a dumbed down example of what I am trying to obtain:
person table:
id | parent
1 | NULL
2 | 1
3 | 1
4 | 2
5 | 2
6 | 3
Where:
1
is the grandparent ("depth 0")2
and 3
are the parents ("depth 1")4
, 5
and 6
are the children ("depth 2")event table:
id | person
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5
6 | 6
Ideally, I would get:
[
{id:1, event_count: 6},
{id:2, event_count: 3},
{id:3, event_count: 2},
{id:4, event_count: 1},
{id:5, event_count: 1},
{id:6, event_count: 1},
]
... which would be the aggregated count()
of all events of self
, and all children, for each Person
object.
Great, many thanks to all who contributed! :)
Will this materialise in a 1.2.1 or something?
@plopidou Did you get this working where you can recursively roll-up the values to the grandparent? I have only figured out how to accumulate the values to the leaves/children.
Hi,
Imagine the following models:
Now I would like to get the count() of all the events for a tree/family of
Person
objects. I am not sure I am doing correctly, but if I am, something is not working? (SubqueryCount is local and confirmed to work)and the trace looks like the following:
Any idea?
thanks!