jackabe
jackabe

Reputation: 365

TypeORM OneToMany query fails

TypeORM is making a weird query of clientId. I have a store and a client table. A client can have many stores. A store can have a client.

I have tried using the ManyToOne and OneToMany relationship.

Store:

@ManyToOne(type => ClientRelationalEntity, client => client.stores)
client: ClientRelationalEntity;

Client:

@OneToMany(type => StoreRelationalEntity, store => store.client)
stores: StoreRelationalEntity[];

I get a query error:

ER_BAD_FIELD_ERROR: Unknown column 'StoreRelationalEntity.clientId' in 'field list'

'id' is being added to client. If I change the id variable in client.js to 'fgfgfg' the error is:

ER_BAD_FIELD_ERROR: Unknown column 'StoreRelationalEntity.clientfgfgfg' in 'field list'

What am I doing wrong here?

Upvotes: 2

Views: 5139

Answers (1)

Tan Nguyen
Tan Nguyen

Reputation: 11

Try following code this may help you.

// Store
@ManyToOne(type => ClientRelationalEntity, client => client.id)
client: ClientRelationalEntity;

// Client:
@OneToMany(type => StoreRelationalEntity, store => store.client)
stores: StoreRelationalEntity[];

Upvotes: 1

Related Questions