{"action":"opened","issue":{"url":"https://api.github.com/repos/aldeed/meteor-autoform/issues/1485","repository_url":"https://api.github.com/repos/aldeed/meteor-autoform","labels_url":"https://api.github.com/repos/aldeed/meteor-autoform/issues/1485/labels{/name}","comments_url":"https://api.github.com/repos/aldeed/meteor-autoform/issues/1485/comments","events_url":"https://api.github.com/repos/aldeed/meteor-autoform/issues/1485/events","html_url":"https://github.com/aldeed/meteor-autoform/issues/1485","id":159398473,"number":1485,"title":"quickForm update with nested array schema","user":{"login":"z1ppz","id":8957530,"avatar_url":"https://avatars.githubusercontent.com/u/8957530?v=3","gravatar_id":"","url":"https://api.github.com/users/z1ppz","html_url":"https://github.com/z1ppz","followers_url":"https://api.github.com/users/z1ppz/followers","following_url":"https://api.github.com/users/z1ppz/following{/other_user}","gists_url":"https://api.github.com/users/z1ppz/gists{/gist_id}","starred_url":"https://api.github.com/users/z1ppz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/z1ppz/subscriptions","organizations_url":"https://api.github.com/users/z1ppz/orgs","repos_url":"https://api.github.com/users/z1ppz/repos","events_url":"https://api.github.com/users/z1ppz/events{/privacy}","received_events_url":"https://api.github.com/users/z1ppz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-09T12:44:02Z","updated_at":"2016-06-09T12:44:02Z","closed_at":null,"body":"Hello world!\r\n\r\nI'm not completely sure if this issue has been made by another post but I will try and see if there is anyone who knows how I can tackle it.\r\n\r\nWe are trying to update a collection which has an schema object that is an array. We can insert values and create as many array objects that we like; but we cannot update the doc.\r\n\r\nThis is the code:\r\n\r\nHappeningAddress = new SimpleSchema({\r\n    addressLinePrimary: {\r\n        type: String,\r\n        label: \"Address line 1\",\r\n        max: 200,\r\n        optional: true\r\n    },\r\n    addressLineSecondary: {\r\n        type: String,\r\n        label: \"Address line 2\",\r\n        max: 200,\r\n        optional: true\r\n    },\r\n    city: {\r\n        type: String,\r\n        optional: true\r\n    },\r\n    zip: {\r\n        type: Number,\r\n        regEx: /^[0-9]{5}$/,\r\n        optional: true\r\n    },\r\n    country: {\r\n       type: String,\r\n        label: \"Country\",\r\n        allowedValues: ['Sweden', 'Norway'],\r\n        optional: true\r\n    },\r\n        // Force value to be current date (on server) upon insert\r\n    // and prevent updates thereafter.\r\n    createdAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isInsert) {\r\n            return new Date();\r\n          } else if (this.isUpsert) {\r\n            return {$setOnInsert: new Date()};\r\n          } else {\r\n            this.unset();  // Prevent user from supplying their own value\r\n          }\r\n        },\r\n              autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      },\r\n    // Force value to be current date (on server) upon update\r\n    // and don't allow it to be set upon insert.\r\n    updatedAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isUpdate) {\r\n            return new Date();\r\n          }\r\n        },\r\n        denyInsert: true,\r\n        optional: true,\r\n              autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      }\r\n}); \r\n\r\nHappeningDescription = new SimpleSchema({\r\n    name: {\r\n        type: String,\r\n        max: 500\r\n    },\r\n    description: {\r\n        type: String,\r\n        max: 5000,\r\n        optional: true\r\n    },\r\n    happeningType: {\r\n        type: String,\r\n        label: \"Event type\",\r\n        allowedValues: ['Public', 'Private']\r\n    },\r\n    happeningAddress: {\r\n      type: HappeningAddress\r\n    },\r\n    happeningPicture: {\r\n        type: Object,\r\n        optional: true\r\n    },\r\n    happeningDate: { // need a calendar\r\n        type: Date,\r\n        optional: true\r\n    },\r\n    // Force value to be current date (on server) upon insert\r\n    // and prevent updates thereafter.\r\n    createdAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isInsert) {\r\n            return new Date();\r\n          } else if (this.isUpsert) {\r\n            return {$setOnInsert: new Date()};\r\n          } else {\r\n            this.unset();  // Prevent user from supplying their own value\r\n          }\r\n        },\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      },\r\n    // Force value to be current date (on server) upon update\r\n    // and don't allow it to be set upon insert.\r\n    updatedAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isUpdate) {\r\n            return new Date();\r\n          }\r\n        },\r\n        denyInsert: true,\r\n        optional: true,\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      }\r\n    });\r\n\r\nAgendaDescription = new SimpleSchema({\r\n    name: {\r\n        type: String,\r\n        max: 500,\r\n        optional: true\r\n    },\r\n    description: {\r\n        type: String,\r\n        max: 5000,\r\n        optional: true\r\n    },\r\n    agendaPicture: {\r\n        type: Object,\r\n        optional: true\r\n    },\r\n    // Force value to be current date (on server) upon insert\r\n    // and prevent updates thereafter.\r\n    createdAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isInsert) {\r\n            return new Date();\r\n          } else if (this.isUpsert) {\r\n            return {$setOnInsert: new Date()};\r\n          } else {\r\n            this.unset();  // Prevent user from supplying their own value\r\n          }\r\n        },\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      },\r\n    // Force value to be current date (on server) upon update\r\n    // and don't allow it to be set upon insert.\r\n    updatedAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isUpdate) {\r\n            return new Date();\r\n          }\r\n        },\r\n        denyInsert: true,\r\n        optional: true,\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      }\r\n    });\r\n\r\nAgendaItem = new SimpleSchema({\r\n    name: {\r\n        type: String,\r\n        max: 500,\r\n        optional: true\r\n    },\r\n    description: {\r\n        type: String,\r\n        max: 5000,\r\n        optional: true\r\n    },\r\n    itemPicture: {\r\n        type: Object,\r\n        optional: true\r\n    },\r\n    itemStart: {\r\n        type: Date,\r\n        optional: true\r\n    },\r\n    itemStop: { // calendar / time?\r\n        type: Date,\r\n        optional: true\r\n    }, \r\n    // Force value to be current date (on server) upon insert\r\n    // and prevent updates thereafter.\r\n    createdAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isInsert) {\r\n            return new Date();\r\n          } else if (this.isUpsert) {\r\n            return {$setOnInsert: new Date()};\r\n          } else {\r\n            this.unset();  // Prevent user from supplying their own value\r\n          }\r\n        },\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      },\r\n    // Force value to be current date (on server) upon update\r\n    // and don't allow it to be set upon insert.\r\n    updatedAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isUpdate) {\r\n            return new Date();\r\n          }\r\n        },\r\n        denyInsert: true,\r\n        optional: true,\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      }\r\n    });\r\n\r\nAgenda = new SimpleSchema({\r\n    agendaAuthor: {\r\n        type: String,\r\n        autoValue: function(){\r\n          return this.userId\r\n        },\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n    },\r\n    agendaDescription: {\r\n        type: AgendaDescription,\r\n        optional: true\r\n    },\r\n    agendaDisplay: {\r\n        type: Boolean,\r\n        defaultValue: true,\r\n        optional: true,\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n    },\r\n    agendaItem: {\r\n      type: [AgendaItem],\r\n      optional: true\r\n    },\r\n    // Force value to be current date (on server) upon insert\r\n    // and prevent updates thereafter.\r\n    createdAt: {\r\n        type: Date,\r\n        label: \"Created At\",\r\n        autoValue: function() {\r\n          if (this.isInsert) {\r\n            return new Date();\r\n          } else if (this.isUpsert) {\r\n            return {$setOnInsert: new Date()};\r\n          } else {\r\n            this.unset();  // Prevent user from supplying their own value\r\n          } \r\n        },\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      },\r\n    // Force value to be current date (on server) upon update\r\n    // and don't allow it to be set upon insert.\r\n    updatedAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isUpdate) {\r\n            return new Date();\r\n          }\r\n        },\r\n        denyInsert: true,\r\n        optional: true,\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      }\r\n    });\r\n\r\nHappening = new SimpleSchema({\r\n    happeningAuthor: {\r\n        type: String,\r\n        autoValue: function(){\r\n          return this.userId\r\n        },\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n    },\r\n    happeningDescription: {\r\n        type: HappeningDescription,\r\n        optional: true // done\r\n    },\r\n    happeningDisplay: {\r\n        type: Boolean,\r\n        defaultValue: true,\r\n        optional: true,\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n    },\r\n      agenda: {\r\n      type: [Agenda],        <---------------------------- THIS IS WHAT I WANT TO UPDATE\r\n      optional: true\r\n     },\r\n    // Force value to be current date (on server) upon insert\r\n    // and prevent updates thereafter.\r\n    createdAt: {\r\n        type: Date,\r\n        label: \"Created At\",\r\n        autoValue: function() {\r\n          if (this.isInsert) {\r\n            return new Date();\r\n          } else if (this.isUpsert) {\r\n            return {$setOnInsert: new Date()};\r\n          } else {\r\n            this.unset();  // Prevent user from supplying their own value\r\n          } \r\n        },\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      },\r\n    // Force value to be current date (on server) upon update\r\n    // and don't allow it to be set upon insert.\r\n    updatedAt: {\r\n        type: Date,\r\n        autoValue: function() {\r\n          if (this.isUpdate) {\r\n            return new Date();\r\n          }\r\n        },\r\n        denyInsert: true,\r\n        optional: true,\r\n        autoform: {\r\n          type: \"hidden\"\r\n        }\r\n      }\r\n    });\r\n\r\nHappenings.attachSchema(Happening); \r\n\r\n______________________________________________________________________________\r\n  Happenings.allow({\r\n  insert: function(userId, doc){\r\n\treturn true;\r\n  },\r\n  update: function(userId, doc) {\r\n    // only allow updating if you are logged in\r\n   return true; \r\n  }\r\n_____________________________________________________________________________\r\n<template name=\"UpdHappening\">\r\n\r\nTemplate.Happenings.helpers({\r\n\tgetDocument: function() {\r\n\t\tvar id = FlowRouter.getParam('id');\r\n\t\tvar doc = Happenings.findOne(id) || {};\r\n\t\treturn doc;\r\n\t}\r\n});\r\n_______________________________________________________________________________\r\n  <div class=\"container\">\r\n    {{#if Template.subscriptionsReady}}\r\n      {{#with getDocument }}\r\n        {{> quickForm collection=\"Happenings\" scope=\"agenda\" doc=this id=\"updateHappeningForm\" type=\"update\" class=\"upd-happening-form\" }}\r\n      {{/with}}\r\n    {{else}}\r\n      Loading...\r\n    {{/if}}\r\n  </div>\r\n\t\r\n</template>\r\n\r\n\r\nAny help would be much appreciated!\r\n\r\nBest regards,\r\nSeph"}}
{"actor":{"display_login":"z1ppz"}}