{"action":"opened","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/team-project/issues/390","repository_url":"https://api.github.com/repos/ga-wdi-boston/team-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/team-project/issues/390/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/team-project/issues/390/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/team-project/issues/390/events","html_url":"https://github.com/ga-wdi-boston/team-project/issues/390","id":249055347,"number":390,"title":"Trouble patching an array","user":{"login":"bradleyden","id":28875814,"avatar_url":"https://avatars1.githubusercontent.com/u/28875814?v=4","gravatar_id":"","url":"https://api.github.com/users/bradleyden","html_url":"https://github.com/bradleyden","followers_url":"https://api.github.com/users/bradleyden/followers","following_url":"https://api.github.com/users/bradleyden/following{/other_user}","gists_url":"https://api.github.com/users/bradleyden/gists{/gist_id}","starred_url":"https://api.github.com/users/bradleyden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradleyden/subscriptions","organizations_url":"https://api.github.com/users/bradleyden/orgs","repos_url":"https://api.github.com/users/bradleyden/repos","events_url":"https://api.github.com/users/bradleyden/events{/privacy}","received_events_url":"https://api.github.com/users/bradleyden/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-09T14:44:30Z","updated_at":"2017-08-09T14:44:30Z","closed_at":null,"body":"This is a bit of a continuation from my issue yesterday, but here's my situation:\r\n\r\nI am trying to patch the resource \"orders\" which has a \"products\" field which is an array, and I'm trying to send a patch request that replaces the products field with a new array, made up of objects.\r\n\r\nWhen I run the request, it says that it is successful, but when I check the orders, the products array in the order I'm trying to patch is the same. I've tried sending the data to Mongoose as both JSON and a JavaScript object, but in both cases I just get a successful response on the request, but the array is not changing.\r\n\r\nThis is how the data is being formatted: \r\n\r\norders[id]:598b1ad01d321d26437f1bce\r\norders[date_placed]:1969/01/01\r\norders[isOpen]:true\r\norders[user_id]:59887f5458fa7b1e22d29175\r\norders[products][0][product_id]:59887fbc58fa7b1e22d29176\r\norders[products][0][quantity]:4\r\norders[products][1][product_id]:598888d64167bd24dc38ffad\r\norders[products][1][quantity]:2\r\norders[products][2][product_id]:5988812358fa7b1e22d29177\r\norders[products][2][quantity]:1\r\n\r\nThis is the object I'm trying to patch, after the previous request was sent:\r\n```json\r\n{\r\n\"orders\": [\r\n{\r\n\"_id\": \"598b1ad01d321d26437f1bce\",\r\n\"updatedAt\": \"2017-08-09T14:32:53.084Z\",\r\n\"createdAt\": \"2017-08-09T14:23:12.743Z\",\r\n\"date_placed\": \"2017-08-07T04:00:00.000Z\",\r\n\"isOpen\": true,\r\n\"_owner\": \"59887f5458fa7b1e22d29175\",\r\n\"__v\": 0,\r\n\"products\": [\r\n\"7\"\r\n],\r\n\"id\": \"598b1ad01d321d26437f1bce\",\r\n\"editable\": false\r\n}\r\n]\r\n}\r\n```\r\nAs you can see, the products array does not reflect any kind of change that I am expecting it to.\r\n\r\nFinally, here is my schema:\r\n```javascript\r\nconst mongoose = require('mongoose')\r\n\r\nconst orderSchema = new mongoose.Schema({\r\n  date_placed: {\r\n    type: Date,\r\n    required: true\r\n  },\r\n  products: {\r\n    type: [{}]\r\n  },\r\n  isOpen: {\r\n    type: Boolean,\r\n    required: true\r\n  },\r\n  _owner: {\r\n    type: mongoose.Schema.Types.ObjectId,\r\n    ref: 'User',\r\n    required: true\r\n  }\r\n}, {\r\n  timestamps: true,\r\n  toJSON: {\r\n    virtuals: false,\r\n    transform: function (doc, ret, options) {\r\n      const userId = (options.user && options.user._id) || false\r\n      ret.editable = userId && userId.equals(doc._owner)\r\n      return ret\r\n    }\r\n  }\r\n})\r\n\r\nconst Order = mongoose.model('Order', orderSchema)\r\n\r\nmodule.exports = Order\r\n```\r\nI've been trying to get this one patch request to work since yesterday around lunchtime and I'm having no luck at all with figuring out how to deal with complex data types in Mongoose, and I wish I could just use SQL and a join table to approach this problem.\r\n\r\nThanks for any help on this!"}}
{"actor":{"display_login":"bradleyden"}}