I'm attempting to run the following type of query using createQueryBuilder
. I've verified that all of my entities are properly created and joined. However, running the following returns an empty array:
let apiKey = await getConnection()
.createQueryBuilder()
.from(ApiKey, "apiKey")
.innerJoinAndSelect("apiKey.site", "site")
.where("site.domain = :domain", { domain: "mysitename.com" })
.andWhere("apiKey.key = :key", { key })
.getMany()
But! When I replace getMany()
with getSql()
, copy the raw SQL and run it, it works! I get the result I expected:
SELECT "site"."id" AS "site_id", "site"."domain" AS "site_domain", "site"."name" AS "site_name", "site"."createdAt" AS "site_createdAt", "site"."apiKeyId" AS "site_apiKeyId", "site"."userId" AS "site_userId" FROM "api_key" "apiKey" INNER JOIN "site" "site" ON "site"."id"="apiKey"."siteId" WHERE "site"."domain" = 'mysitename.com'
Is there any thing obviously wrong with how I'm trying to build this query?
Thanks in advance for the help!
.getMany() returns type Promise of Entity[], and given the nature of your query, I suspect you are not returning an entity at all. Try .getRawMany() or .getRawAndEntities()
See the documentation on QueryBuilder here for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With