kpfromer / nestjs-typegoose

Typegoose with NestJS
https://kpfromer.github.io/nestjs-typegoose/
MIT License
291 stars 71 forks source link

Discriminator properties not working, only base class. #435

Closed ENiGMA9 closed 3 years ago

ENiGMA9 commented 3 years ago

Hello, I have the following issue I've been debugging for the past 3 hours.

I have a base class and some classes that extend it. I properly declared the discriminators.

When creating a new document through a discriminator class, the discriminator key is there in the document so it's properly recognized, but only the props from the base class default-filled or interactable at all. Declaring default values does nothing, trying to update it afterwards does nothing, nothing works, no set, no mark edited, no update, no save.

When moving the respective field to the base class it's properly created with default values, and editable as it should be too.

EDIT: The field I needed was an extended model as well with discriminator, but somehow this one works, goes through validation, updates well. I guess the issue is when directly creating

EDIT2: I will leave this here for posterity if that's ok with you. As a statement and a reminder, to NEVER name your classes too close to 'reserved' keywords because bad stuff can happen. I just lost 3 hours because I'm dumb. I wrote this code days ago, not now, but just now got to test this class. It's incredible it inserted into the db with the discriminator and model loaded at all. My classname was Test image

Renaming this as a last resort because I thought maybe there's some wonky js around here seeing others work, I discovered days ago auto-import got me dirty: image

That's all folks, careful with class names :/