typeorm / typeorm

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
http://typeorm.io
MIT License
33.46k stars 6.21k forks source link

Where expression on createDescendantsQueryBuilder not working (?) #10522

Open RafifWibowo opened 5 months ago

RafifWibowo commented 5 months ago

Issue description

I want to use createDescendantsQueryBuilder, when i'm not using where statement i have no issue. But, when i use where expression, it return all the descendants from any other roots as well, not just root that included at the builder.

Expected Behavior

first uuid are the root(318ec885-2ec0-452b-8826-6aa87a4d6f50) and the other are the children

      {
        "uuid": "318ec885-2ec0-452b-8826-6aa87a4d6f50"
      },
      {
        "uuid": "436dcacc-7dc4-43b7-9bb3-9d8084814b5a"
      },
      {
        "uuid": "5b18f3d6-5d0e-429d-80ca-5d0de3c64d69"
      }
    ]

Actual Behavior

return all of enities even tough they were not children of root(318ec885-2ec0-452b-8826-6aa87a4d6f50)

      {
        "uuid": "0d444e2e-bfaa-4e89-a194-d52e03f99496"
      },
      {
        "uuid": "318ec885-2ec0-452b-8826-6aa87a4d6f50"
      },
      {
        "uuid": "436dcacc-7dc4-43b7-9bb3-9d8084814b5a"
      },
      {
        "uuid": "5b18f3d6-5d0e-429d-80ca-5d0de3c64d69"
      },
      {
        "uuid": "78c5e01b-7305-4aa6-a37f-e3a1d999dfb6"
      },
      {
        "uuid": "9a9ca621-cf94-40fb-9ee3-fbfeb8dc0c44"
      },
      {
        "uuid": "ea60f1eb-0733-46f6-9a0b-48d8b30e420c"
      }
    ]

Steps to reproduce

i have no idea

My Environment

Dependency Version
Operating System Windows
Node.js version 18.16.0
Typescript version 5.2.2
TypeORM version 0.2.41

Additional Context

this is the code that i used, document.uuid = "318ec885-2ec0-452b-8826-6aa87a4d6f50"

   const docs = await getTreeRepository(Document)
      .createDescendantsQueryBuilder("doc", "docClosure", document)
      .where(
        new Brackets((qb) => {
          qb.where(`JSON_EXTRACT(content, '$.content[*].content[*].text') LIKE :search_string`, { search_string: `%${search}%` })
            .orWhere(`JSON_EXTRACT(content, '$.content[*].content[*].cotent[*].text') LIKE :search_string`, { search_string: `%${search}%` });
        })
      )
      .getMany();

Relevant Database Driver(s)

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

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

ubudragon commented 2 months ago

you have to use .andWhere(... instead of .where(...