CodeDredd / pinia-orm

The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.
https://pinia-orm.codedredd.de/
MIT License
430 stars 37 forks source link

Both Query.orderBy and UseCollect.sortBy are broken #1858

Open daniser opened 1 month ago

daniser commented 1 month ago

Environment

No response

Reproduction

Unfortunately I have no free time right now to craft a minimal reproduction. I will return here and make it when I'll have spare time.

Describe the bug

I have complex sorting logic which worked in Pinia ORM 1.7.2 but stopped working in 1.9.1. It's no more reactive, and sorting order differs between versions. I don't know exactly what's wrong, it needs further investigation.

I just put this information here so @CodeDredd and others know there's a problem and maybe dig into it if interested.

Additional context

My usage (I know it's cumbersome but I can't do minimal repro at this time):

<script setup lang="ts">
import { useRepo } from "pinia-orm";
import { useCollect } from "pinia-orm/helpers";

const operatorRepo = computed(() => useRepo(OperatorRepository));
const ticketRepo = computed(() => useRepo(TicketRepository));

const sortedOperators = computed(() =>
    useCollect(
        operatorRepo.value
            .with("tickets", (query) => {
                query.with("category").where("meta", metaFilter).orderBy(mode.value, "desc");
            })
            .whereHas("tickets")
            .orWhere((operator: OperatorModel) => !options.hideEmpty && operator.online)
            .get(),
    ).sortBy([
        ["online", "desc"],
        ["ready", "desc"],
        ["free_slots", "desc"],
        ["ticket_count", "asc"],
        ["name", "asc"],
    ]),
);

const sortedTickets = computed(() =>
    ticketRepo.value.unbound().with("category").where("meta", metaFilter).orderBy(mode.value, "desc").get(),
);
</script>

Logs

No response

CodeDredd commented 1 month ago

@daniser Thank's for the head ups. Lookings forward for the reporduction, because with out it it's gonna hard to find and fix.