You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're encountering the following error when trying to add a new many-to-many association between two entities:
TypeError: Cannot read property 'constructor' of undefined
To be clear, we are not tracking changes on these entities (no @TrackChanges decorator), so getting an error from nestjs-changelog is quite unexpected. After some investigation, I figured out that the problem is a missing check for whether an entity is included in the event that notifies of a new insertion, here:
So this problem will be seen anytime there's something being inserted into the database which has not been marked with the @Entity decorator, as is the case for the join table created by TypeORM for a many-to-many relationship.
Workaround
One possibility, at least for this case, is to explicitly define an entity class for the join table (i.e., don't let TypeORM create it), which means you'll add the @Entity decorator, getting rid of the problem. However, this is not a simple change.
The easiest way I found around this is to use ChangeSubscriber.disableTracking to wrap the save() call. But of course, this may not be desirable if you are saving things that you want tracking on.
The text was updated successfully, but these errors were encountered:
Description
We're encountering the following error when trying to add a new many-to-many association between two entities:
TypeError: Cannot read property 'constructor' of undefined
To be clear, we are not tracking changes on these entities (no
@TrackChanges
decorator), so getting an error fromnestjs-changelog
is quite unexpected. After some investigation, I figured out that the problem is a missing check for whether an entity is included in the event that notifies of a new insertion, here:nestjs-changelog/lib/change.subscriber.ts
Line 26 in b129bd2
So this problem will be seen anytime there's something being inserted into the database which has not been marked with the
@Entity
decorator, as is the case for the join table created by TypeORM for a many-to-many relationship.Workaround
One possibility, at least for this case, is to explicitly define an entity class for the join table (i.e., don't let TypeORM create it), which means you'll add the
@Entity
decorator, getting rid of the problem. However, this is not a simple change.The easiest way I found around this is to use
ChangeSubscriber.disableTracking
to wrap thesave()
call. But of course, this may not be desirable if you are saving things that you want tracking on.The text was updated successfully, but these errors were encountered: