I'm using TypeORM with JS and it's docs are super minimal, so I couldn't find the solution for my question over there. I want to create a one-to-many bi-directional relationship and can't get over the following exception:
TypeORMError: Entity metadata for Team#groups was not found. Check if you specified a correct entity object and if it's connected in the connection options.
Thats the definition of the two entities (one team might have multiple groups):
module.exports = new EntitySchema({
name: 'Team',
tableName: 'team',
columns: {
id: {
primary: true,
type: 'uuid',
generated: true,
},
name: {
type: 'varchar',
},
},
relations: {
groups: {
target: 'TeamGroups',
type: 'one-to-many',
inverseSide: 'team_id',
},
},
})
module.exports = new EntitySchema({
name: 'TeamsGroups',
tableName: 'team_group',
columns: {
team_id: {
primary: true,
type: 'uuid',
},
group_id: {
primary: true,
type: 'uuid',
},
},
relations: {
team_id: {
target: 'Team',
type: 'many-to-one',
joinColumn: true,
},
},
})
What am I missing?
I can't test but I'm fairly sure it's this, looking at the error & docs:
module.exports = new EntitySchema({
name: 'Team',
tableName: 'team',
columns: {
id: {
primary: true,
type: 'uuid',
generated: true,
},
name: {
type: 'varchar',
},
},
relations: {
TeamGroups: {
target: 'TeamGroups',
type: 'one-to-many',
inverseSide: 'team_id',
},
},
})
module.exports = new EntitySchema({
name: 'TeamsGroups',
tableName: 'team_group',
columns: {
team_id: {
primary: true,
type: 'uuid',
},
group_id: {
primary: true,
type: 'uuid',
},
},
relations: {
Team: {
target: 'Team',
type: 'many-to-one',
joinColumn: true,
},
},
})