-
Notifications
You must be signed in to change notification settings - Fork 642
Open
Description
Objection.js version: 3.1.5
Node.js version: 20.11
Db engine: postgres
I have a User Model with a relation on events:
class User extends Model {
static get relationMappings() {
return {
events: {
relation: Model.HasManyRelation,
modelClass: "Event",
join: {
from: "users.id",
to: "events.userId",
},
modify(qb) {
qb.orderBy("id", "desc");
},
},
};
}
}when i try to get the total count of events for a user:
const query = user.$relatedQuery("events")
query.has("orderBy") // false
const totalCount = await query.resultSize()Despite the this.clone().clear(/orderBy|offset|limit/);, the ORDER BY clause remains, resulting in a less performant query:
SELECT count(*) AS "count" FROM (
SELECT "events".* FROM "events"
WHERE "events"."user_id" IN (?)
ORDER BY "id" DESC
) AS "temp";Operations applied in modifiers do not seem to be recorded on the queryBuilder object. Is it intentional?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels