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

toObject uses wrong transform for subdocs #1412

Closed
mtsr opened this issue Apr 2, 2013 · 0 comments
Closed

toObject uses wrong transform for subdocs #1412

mtsr opened this issue Apr 2, 2013 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@mtsr
Copy link

mtsr commented Apr 2, 2013

As can be seen in the minimal reproduction here, when a schema and its subdoc both have transforms defined, the top-level transform is used for the subdoc as well.

Expected output:

{ _id: 515aef8c2b98ec5125000001,
  second: 
   [ { _id: 515aef8c2b98ec5125000002, secondToObject: true },
     { _id: 515aef8c2b98ec5125000003, secondToObject: true } ],
  firstToObject: true }

Actual output:

{ _id: 515aef8c2b98ec5125000001,
  second: 
   [ { _id: 515aef8c2b98ec5125000002, firstToObject: true },
     { _id: 515aef8c2b98ec5125000003, firstToObject: true } ],
  firstToObject: true }

In the gist I also included a workaround, as all actual fixes to mongoose I tried broke a bunch of tests. In my opinion this problem is caused by Document.prototype.toObject actually changing the options object. If anything it should change a clone, but that breaks a bunch of tests right now.

aheckmann added a commit that referenced this issue Aug 21, 2013
fixed #1412; Subdocuments use their own transform
ebensing added a commit to mongodbinc-interns/mongoose that referenced this issue Aug 21, 2013
Made it such that subdocuments will use their own transform function
instead of their parent's when `toObject()` is called
ebensing added a commit that referenced this issue Aug 21, 2013
Made it such that subdocuments will use their own transform function
instead of their parent's when `toObject()` is called
aheckmann added a commit that referenced this issue Aug 21, 2013
ebensing added a commit that referenced this issue Aug 23, 2013
Made it such that subdocuments will use their own transform function
instead of their parent's when `toObject()` is called
aheckmann added a commit that referenced this issue Aug 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

1 participant