Closed wonder95 closed 3 months ago
You can use sub-query instead of inner-join. In that case you'll be able to set order-by for dues_id.
Hey @wonder95, does using a sub query solve your problem? If not, could you please try to PR a failing test (and mention this issue)? That would make reproducing this issue a lot easier on our end. Thanks!
I have been trying to add a simple sort to a query to sort by a date field in a related table (see here for details), and have the following code:
with this resource
this works well enough, but I want it to be in descending date order by
payments.payment_date
. So, following the docs, I add a-
todefaultSort()
like soHowever, when I do that , my site breaks, because no
payments
data is returned. Looking at the generated queries, I get thisfor both cases, with the only difference being I get
DESC
in the second query (as expected). However, the problem is the next queries that are generated.First, it gets the user record for first item in the list, which is fine.
and the next query is where it gets the
payments
recordThe problem is, though, that the query is using the wrong
payments
table field to get the data fordues_id
. In the ascending sort, theid
anddues_id
values are the same, they work. But you can see it in the descending sort because the two numbers don't match. For instance, in what would be the first record in descending order,id
is1526
, anddues_id
=1185
, so the correct query would bebut instead it is
I use these models (
Dues
andPayment
) all over my site without issue, so I know I have them defined correctly.For grins, here are my relationship definitions, first
Payment
and
Dues
:I stepped through the code via debugger, and I can see that the
DESC
is applied to the query correctly. The issue is that the wrong column is being used in the join for some reason, even though this is correct.Is this indeed a QB bug? Or am I doing something wrong?