Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transform nested embedded array column overwritten undefined (mongodb) #4511

Closed
wants to merge 1 commit into from

Conversation

tilfin
Copy link

@tilfin tilfin commented Jul 30, 2019

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

export class Post {
  @Column()
  title: string

  @Column()
  comments: Comment[]
}

export class Comment {
  @Column()
  text: string

  @Column(type => Attachment)
  attachments: Attachment[]  // new column added

  constructor() {
    this.attachments = [] // added
  }
}

export class Attachment {
  @Column()
  subject: string
}
...
const oldPost = new Post()
oldPost.title = 'title'
const comment  = new Comment()
comment.text = 'hello'
oldPost.comments = [comments]
await repo.save(oldPost); // before attachments column is added

// Add attachments to Comment

const [post] = await repo.find();
post.comments[0].attachments  // is undefined, empty array expected

For example, adding new column to a collection, existtant documents have no columns in DB.
I want to set the column default value in the constructor and then I can handle it without whether its value is null or not.

I think that skipping the assignment of columns that has no value should be implemented in the commit (0ae68e4#diff-5ca83022308e329a128f5a2bf58ba6c8).

resolve that default values whose columns are embbed document of embedded array
not to be overwritten with undefined
@rustamwin
Copy link
Contributor

Hmm. This will be a continuation of the #3900

@pleerock
Copy link
Member

pleerock commented Sep 5, 2019

@rustamwin how it is?

@pleerock
Copy link
Member

pleerock commented Sep 5, 2019

I'm not sure if we should merge this change or not. In relational databases we completely ignore undefined properties and it works great.

However for mongodb it feels debatable. Reason is different way of storing things by mongo and mongo being schemaless on its own.

What if user wants to completely remove some property from the document? Such changes would make it impossible, but such task feels absolutely natural for mongodb usage.

@AlexMesser
Copy link
Collaborator

Looks like current implementation is by design. Closing.

@AlexMesser AlexMesser closed this May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants