Typeorm: How to I omit certain columns in a relation?

Created on 11 Oct 2017  路  3Comments  路  Source: typeorm/typeorm

So I have a Restaurant entity that has a relation to User that represents it's owner, I'm currently trying to find a restaurant and including the owner information but I can't find out how omit certain fields in relations, in this case a password field.

const [findErr, restaurant] = await to(Restaurant.find({
       relations: ['logo', 'owner'],
       skip: page * limit,
       take: limit
   }));

Most helpful comment

@mkamranhamid You can select the columns you need with the select property which overrides @Column({ select: false }):

const user = await userRepository.findOne({ where: { email }, select: ['id', 'password'] });

All 3 comments

The easiest you can do is to use select: false option in column of your password:

@Column({ select: false })
password: string

Other options are involving using of QueryBuilder.

The easiest you can do is to use select: false option in column of your password:

@Column({ select: false })
password: string

Other options are involving using of QueryBuilder.

how do you login with
ts @Column({ select: false }) password: string
how do you compare hash ?

@mkamranhamid You can select the columns you need with the select property which overrides @Column({ select: false }):

const user = await userRepository.findOne({ where: { email }, select: ['id', 'password'] });

Was this page helpful?
0 / 5 - 0 ratings