Select columns from join table - TypeOrm

Viewed 2825

I have a join query like bellow and i'm trying to convert it to typeOrm query

SELECT a.actionName 
FROM walletAppActions wa 
INNER JOIN actions a on a.actionId = wa.actionId 
WHERE wa.appId = 1

ActionConfig.entity.ts

@Entity('actions')
export class WalletAppActionsEntity{
    @PrimaryGeneratedColumn("increment")
    actionId: number;  

    @Column()
    actionName: string;

    @OneToOne( type => Actions , config => config.action)
    config: Actions;
}

appActions.entity.ts

@Entity('walletAppActions')
export class Actions{
    @PrimaryGeneratedColumn("increment")
    id: number;  

    @Column()
    appId: number;

    @Column()
    actionId: number;

    @OneToOne( type => WalletAppActionsEntity , action => action.config)
    action: WalletAppActionsEntity;

}

table structure has attached here

walletAppActions table

walletAppActions

Actions table

actions

1 Answers

Try this

let data=await getManager().getRepository(WalletAppActionsEntity)
            .createQueryBuilder('wa')// where wa is alias
            .leftJoinAndSelect('actions','acti','wa.id = :id',{id:1})//acti is alias
            .getOne();
Related