Skip to content

OrderByCondition prints undefined in SQL when nulls is not provided #8103

Closed

Description

@Yacodo

Issue Description

Expected Behavior

Using OrderByCondition without providing the nulls (that is tagged as optional)

const query = Entity.createQueryBuilder('entity').orderBy({name: { order: "ASC"}})
// Result in SELECT * FROM entity ORDER BY name "ASC"

Actual Behavior

Steps to Reproduce

Actually it prints the undefined (or null) value into the SQL.

const query = Entity.createQueryBuilder('entity').orderBy({name: { order: "ASC"}})
// Result in SELECT * FROM entity ORDER BY name "ASC" undefined

The nullability of this has to do with #4161 to not force user to set it when DB provider does not support it.

The nulls is printed anyway :

return this.replacePropertyNames(columnName) + " " + (orderBys[columnName] as any).order + " " + (orderBys[columnName] as any).nulls;

Possible simple fix would we to changes that line to

  const nullsOrdering = ` ${(orderBys[columnName] as any).nulls || ""}`.trim()
  return this.replacePropertyNames(columnName) + " " + (orderBys[columnName] as any).order + nullsOrdering; 

My Environment

Dependency Version
Operating System Fedora
Node.js version 16.2
Typescript version 4.3.2
TypeORM version 0.2.31

Additional Context

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✅ Yes, I have the time, but I don't know how to start. I would need guidance. (did not read contribute and dunno how much time for that simple fix.)
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue. (I would prefer that ;))

Activity

  1. github-actions commented on Sep 18, 2025

    @github-actions

    TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).

    As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.

    🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
    If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions