sorry for my bad english
@Entity()
export class Account {
@PrimaryGeneratedColumn()
id: number;
@Column({ unique: true })
accountNumber: number;
@Column({ type: 'double precision' })
balance: number;
@OneToOne(() => Currency)
@JoinColumn({ name: 'currency_signature' })
currency: Currency;
@OneToOne(() => User, { nullable: false })
@JoinColumn()
user: User;
}
i have this entity/table in my postgres database(im using typeorm),
if (!user) throw new BadRequestException('There is no user with that id');
const account = await this.accountRepository.create({
...createAccountDto,
user,
currency: { currency_signature: 'USC' },
});
and i have this create query
my question is, do i need to check for the existence of the currency table data first? or just let the account table handle it using foreign key constraint, because the account table know if the data im inserting is in the currency table or not from the foreign key constraint?
from my perspective i think i dont need to make a find query to check the existence of the currency signature first, because the account table already check it for me using foreign_key constraint, if i make a find query to check the existence of the currency, its just going to be another query and just adding extra job to the database?
what do you guys think?
Christian Tiovanto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.