Changes between Version 1 and Version 3 of Ticket #31963
- Timestamp:
- Aug 29, 2020, 7:37:25 AM (4 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #31963
- Property Triage Stage Accepted → Unreviewed
- Property Keywords Database ORM removed
- Property Resolution → worksforme
- Property Status new → closed
- Property Summary Django: Nested OuterRef not woking to access grandparent's ID → Nested OuterRef not woking to access grandparent's ID.
-
Ticket #31963 – Description
v1 v3 1 Trying to access FeeAccountmodel's id using **OuterRef** in a **nested subquery**, but **not immediate parent**. Throwing:1 Trying to access `FeeAccount` model's id using **OuterRef** in a **nested subquery**, but **not immediate parent**. Throwing: 2 2 3 3 `ValueError: This queryset contains a reference to an outer query and may only be used in a subquery.` … … 5 5 6 6 {{{ 7 first_unpaid_fee_schedule_instalment = Subquery(FeeScheduleInstalment.objects \ 8 .annotate( 9 total_balance = Subquery( 10 FeeInstalmentTransaction.objects.filter( 11 account_id=OuterRef(OuterRef('id')), # not working: need grand-parent's id here 12 instalment__schedule=OuterRef('id'), #working: parent's id 13 ) \ 14 .values('balance') \ 15 .annotate(total_balance=Sum('balance')) \ 16 .values('total_balance') 17 ) 18 ) \ 19 .values('id')[:1] 7 first_unpaid_fee_schedule_instalment = Subquery( 8 FeeScheduleInstalment.objects.annotate( 9 total_balance = Subquery( 10 FeeInstalmentTransaction.objects.filter( 11 account_id=OuterRef(OuterRef('id')), # not working: need grand-parent's id here 12 instalment__schedule=OuterRef('id'), #working: parent's id 13 ).values('balance').annotate(total_balance=Sum('balance')).values('total_balance') 14 ), 15 ).values('id')[:1] 20 16 ) 21 17 22 23 fee_accounts_with_first_unpaid = FeeAccount.objects \ 24 .annotate( 25 first_unpaid_schedule = first_unpaid_fee_schedule_instalment, 18 fee_accounts_with_first_unpaid = FeeAccount.objects.annotate( 19 first_unpaid_schedule = first_unpaid_fee_schedule_instalment, 26 20 ) 27 21 }}}