Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
TypeORM - One-To-Many relationship defined in EntitySchema

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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,
    },
  },
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda