I have a entity "Transaction" who has a related entity "Customer". I would like to load the customer related to the transaction.
It works like this:
Repository.find({ relations: ['customer'] });
But I want to do a more complex query, So then I use QueryBuilder
Rrepository.createQueryBuilder('t')
.leftJoin( /*...*/ )
.where( /*...*/ })
.getOne();
This returns the transaction with a null customer.
my Entities are:
@Entity()
export default class Transaction {
...
@ManyToOne(type => Customer, c => c.transactions, { nullable: true, eager: true })
public customer?: Customer;
...
}
and
@Entity()
export default class Customer {
...
@OneToMany(type => Transaction, t => t.customer)
@JoinColumn({ name: 'cust_id', referencedColumnName: 'cust_id' })
public transactions?: Array<Transaction>;
...
}
How can I load the Transaction Customer using the onto a Transaction object using CreateQueryBuilder command?