Crud: [Question] Can I get data with relation is null

Created on 18 Jul 2019  路  4Comments  路  Source: nestjsx/crud

i have two entity

import {Entity, PrimaryGeneratedColumn, Column, ManyToOne} from "typeorm";
import {User} from "./User";

@Entity()
export class Photo {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    url: string;

    @ManyToOne(type => User, user => user.photos)
    user: User;

}
import {Entity, PrimaryGeneratedColumn, Column, OneToMany} from "typeorm";
import {Photo} from "./Photo";
@Entity()
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;

    @OneToMany(type => Photo, photo => photo.user)
    photos: Photo[];

}



md5-2329ec9444f8cc468ce5f138eda9120d



        return this.repo
            .createQueryBuilder('user')
            .leftJoinAndSelect('user.photos', 'photos')
            .getMany();



md5-9b2f647b9bd680472e1094c328c3ced4



{
  id:1,
  name:'test',
  photos:null
}

Is there any way I can get user data which phote data is null in typerom crud join?

thank you.

Most helpful comment

98 WIP

and you can do this for now

// @ts-ignore left join only
TypeOrmCrudService.prototype.getJoinType = function(s: string) {
  return 'leftJoin';
};

All 4 comments

98 WIP

and you can do this for now

// @ts-ignore left join only
TypeOrmCrudService.prototype.getJoinType = function(s: string) {
  return 'leftJoin';
};

@Diluka thank you

98 WIP

and you can do this for now

// @ts-ignore left join only
TypeOrmCrudService.prototype.getJoinType = function(s: string) {
  return 'leftJoin';
};

Where should I put this code? In the service that extends TypeOrmCrudService?

@biammsilva anywhere before you actually use service. I suggest using it like a polyfill.

you can create a patch.ts file and import './patch' in the bootstrap file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lafeuil picture lafeuil  路  5Comments

si-hyeon-ee picture si-hyeon-ee  路  5Comments

cuni0716 picture cuni0716  路  3Comments

cjancsar picture cjancsar  路  4Comments

btd1337 picture btd1337  路  4Comments