#Typeorm "Where" clause in virtual property

2 messages · Page 1 of 1 (latest)

young trench
#

Hi, I am creating a function for users to query rows created by other users, but I want to make sure the user who created the row did not block each other (don't want to see any row created by a blocked user).

this.discoverRepo.createQueryBuilder("d")
        .leftJoinAndSelect("d.user", "user")
        .leftJoinAndSelect("user.profile", "profile")
.leftJoinAndMapOne(
            "d.block", 
            UserBlock, 
            "userBlock", 
            `
                (userBlock.blockerId='${userId}' and userBlock.blockedId=user.id) or
                (userBlock.blockedId='${userId}' and userBlock.blockerId=user.id)
            `)
.andWhere("d.block is null")
.andWhere("user.id != :userId", { userId })
.andWhere("d.status = :status", { status: "ACTIVE" })
.andWhere("d.created_at >= :ttl", { ttl: new Date(Date.now() - CONSTANT.DISCOVER_TTL * 1000) })
.getMany();

where

.andWhere("d.block is null")

throws column d.block does not exist.

Is there proper / alternative way to do this? Thanks🥹

jolly spire
#

.