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

192
Visualizações
How to Assign an Object that got loaded from a Database to its class?

I am currently working on some logging functionality. This Logging is used inside my Repository where the logging is implemented inside a wrapper. At initalisation time the wrapper, and therefor the logging is applied to each function in the Repository. This is kinda working so far. My problem is the with the arguments that get passed to the logged function. These should always be an Object instance from one of my Modelklasses. When these are just got created using the new - operator everything is working fine. Problem is when they got loaded from the Database. I can not use modelArgu instanceof modelto identify if from which Class they got created. Is there any way to resign them to the original model? I need this to know what kind of "uuid" I got to save it to the right param.

// always retrieves uuid from first given argument
function getUuid(model_type, ...args) {
        console.log(args)
        let uuid = null;
        if (args[0] instanceof model_type) {
            uuid = parseInt(args[0].uuid);
        } else if (typeof args[0] === "number") {
            uuid = args[i]
        }
        return uuid;
    }

For example when the passed Object contained in args was just instantiated from some model class the console.log(args) would return Appointment {}which does exactly what I want. But when that argument gets loaded from some database. It instead returns something like:

 {
  uuid: 16,
  description: 'asdfsf',
  owner: 1,
  from: '2022-02-15T09:48',
  to: '2022-02-14T09:48',
  participants: [],
  files: [],
  name: 'sdf'
}

This is still the Object but args[0] instanceof model_type returns false.

about 4 years ago · Juan Pablo Isaza
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