ethanresnick / json-api

Turn your node app into a JSON API server (http://jsonapi.org/)
GNU Lesser General Public License v3.0
268 stars 41 forks source link

PATCH should call update in Mongo adapter #92

Closed seawatts closed 6 years ago

seawatts commented 8 years ago

The current implementation seems to call .save() on the model when issuing a PATCH request. By doing so this calls the mongoose save lifecycle hook I believe calling .update() on the document should fix this. (I haven't tested this out yet)

It also seems that you referenced Mongoose 4.x, which has been released, is this comment just out of date?

ethanresnick commented 6 years ago

Running the save lifecycle hook in v2 was intentional; that approach was used for the more complete validation that the read-then-resave pattern allows. However, it came with other downsides and has been changed in v3 to work as you requested.

See the v3 changelog for details + rationale. https://github.com/ethanresnick/json-api/blob/06519812803fa72aa097ba0a6e88ad1ac3d715c2/UPGRADING.md#mongoose-behaviormongooseadapter