Reputation: 465
So we're trying to check our codes for possible bugs when a resource related to another is deleted. For example, we have a Progress
entity which is related to User
, which is then related to Employee
. The User
entity implements a soft-delete. If we delete a user related to a progress data, then this.logger.log(progress.user.employee)
would return an error. Of course, making user optional (progress.user?
) would solve it, but I was curious if making the User
column optional in the Progress
entity would make any difference at all.
So on the Progress
entity, we have this:
@ManyToOne((_) => User)
@JoinColumn({ name: 'user_id' })
user: User;
I want to know if making this user optional would change anything.
Upvotes: 1
Views: 266
Reputation: 370
A soft delete is when you do not delete the row, but update deleted_at
flag for a particular row. So a user should be always available. Could you add more context as to what you are trying to achieve. Try to be a little verbose in explaining your problem
Upvotes: 1
Reputation: 830
You can check field progress.user at any request and delete relation if it already not exists
Upvotes: 0