{"action":"created","issue":{"url":"https://api.github.com/repos/RobinBuschmann/sequelize-typescript/issues/309","repository_url":"https://api.github.com/repos/RobinBuschmann/sequelize-typescript","labels_url":"https://api.github.com/repos/RobinBuschmann/sequelize-typescript/issues/309/labels{/name}","comments_url":"https://api.github.com/repos/RobinBuschmann/sequelize-typescript/issues/309/comments","events_url":"https://api.github.com/repos/RobinBuschmann/sequelize-typescript/issues/309/events","html_url":"https://github.com/RobinBuschmann/sequelize-typescript/issues/309","id":298094369,"node_id":"MDU6SXNzdWUyOTgwOTQzNjk=","number":309,"title":"Update with associations","user":{"login":"doovers","id":5927611,"node_id":"MDQ6VXNlcjU5Mjc2MTE=","avatar_url":"https://avatars3.githubusercontent.com/u/5927611?v=4","gravatar_id":"","url":"https://api.github.com/users/doovers","html_url":"https://github.com/doovers","followers_url":"https://api.github.com/users/doovers/followers","following_url":"https://api.github.com/users/doovers/following{/other_user}","gists_url":"https://api.github.com/users/doovers/gists{/gist_id}","starred_url":"https://api.github.com/users/doovers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doovers/subscriptions","organizations_url":"https://api.github.com/users/doovers/orgs","repos_url":"https://api.github.com/users/doovers/repos","events_url":"https://api.github.com/users/doovers/events{/privacy}","received_events_url":"https://api.github.com/users/doovers/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-02-18T15:44:39Z","updated_at":"2018-07-20T14:40:31Z","closed_at":"2018-03-22T16:47:59Z","author_association":"NONE","body":"With the following models & associations, how can I perform an update with this JSON?\r\n\r\nI've spent a day trying to do this and don't know why I can't figure it out!\r\n\r\n```json\r\n{\r\n\t\"firstName\": \"firstName1\",\r\n\t\"lastName\": \"lastName1\",\r\n\t\"company\": \"company1\",\r\n\t\"email\": \"email1\",\r\n\t\"isActive\": false,\r\n\t\"notes\": \"notes1\",\r\n\t\"addresses\": [{\r\n\t\t\"street\": \"street1\",\r\n\t\t\"city\": \"city1\",\r\n\t\t\"country\": \"country1\",\r\n\t\t\"region\": \"region1\",\r\n\t\t\"postalCode\": \"postalCode1\"\r\n\t},\r\n\t{\r\n\t\t\"street\": \"street2\",\r\n\t\t\"city\": \"city2\",\r\n\t\t\"country\": \"country2\",\r\n\t\t\"region\": \"region2\",\r\n\t\t\"postalCode\": \"postalCode2\"\r\n\t}],\r\n\t\"phones\": [{\r\n\t\t\"number\": 1234,\r\n\t\t\"extension\": 1234,\r\n\t\t\"type\": \"Cell\"\r\n\t},\r\n\t{\r\n\t\t\"number\": 1234,\r\n\t\t\"extension\": 1234,\r\n\t\t\"type\": \"Home\"\r\n\t}]\r\n}\r\n```\r\n\r\n```typescript\r\nimport { Table, Column, Model, HasOne, HasMany } from 'sequelize-typescript';\r\nimport Address from './address.model';\r\nimport Phone from './phone.model';\r\n\r\n@Table({\r\n  tableName: 'customer',\r\n  timestamps: true\r\n})\r\nexport default class Customer extends Model<Customer> {\r\n\r\n  @Column company: string;\r\n  @Column email: string;\r\n  @Column firstName: string;\r\n  @Column isActive: boolean;\r\n  @Column lastName: string;\r\n  @Column notes: string;\r\n  @HasMany(() => Address, { onDelete: 'cascade' }) addresses: Address[];\r\n  @HasMany(() => Phone, { onDelete: 'cascade' }) phones: Phone[];\r\n\r\n}\r\n```\r\n\r\n```typescript\r\nimport { Table, Column, Model, ForeignKey, BelongsTo } from 'sequelize-typescript';\r\nimport Customer from './customer.model';\r\n\r\n@Table({\r\n  tableName: 'address',\r\n  timestamps: true\r\n})\r\nexport default class Address extends Model<Address> {\r\n\r\n  @Column street: string;\r\n  @Column city: string;\r\n  @Column country: string;\r\n  @Column region: string;\r\n  @Column postalCode: string;\r\n\r\n  @ForeignKey(() => Customer)\r\n  @Column customerId: number;\r\n\r\n  @BelongsTo(() => Customer, { onDelete: 'cascade' })\r\n  customer: Customer;\r\n}\r\n```\r\n\r\n```typescript\r\nimport { Table, Column, Default, DataType, Model, BelongsTo, ForeignKey } from 'sequelize-typescript';\r\nimport Customer from './customer.model';\r\n\r\n@Table({\r\n  tableName: 'phone',\r\n  timestamps: true\r\n})\r\nexport default class Phone extends Model<Phone> {\r\n\r\n  @Column number: string;\r\n  @Column extension?: number;\r\n  @Column type: string;\r\n\r\n  @ForeignKey(() => Customer)\r\n  @Column customerId: number;\r\n\r\n  @BelongsTo(() => Customer, { onDelete: 'cascade' })\r\n  customer: Customer;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/RobinBuschmann/sequelize-typescript/issues/comments/406621096","html_url":"https://github.com/RobinBuschmann/sequelize-typescript/issues/309#issuecomment-406621096","issue_url":"https://api.github.com/repos/RobinBuschmann/sequelize-typescript/issues/309","id":406621096,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjYyMTA5Ng==","user":{"login":"mschipperheyn","id":384959,"node_id":"MDQ6VXNlcjM4NDk1OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/384959?v=4","gravatar_id":"","url":"https://api.github.com/users/mschipperheyn","html_url":"https://github.com/mschipperheyn","followers_url":"https://api.github.com/users/mschipperheyn/followers","following_url":"https://api.github.com/users/mschipperheyn/following{/other_user}","gists_url":"https://api.github.com/users/mschipperheyn/gists{/gist_id}","starred_url":"https://api.github.com/users/mschipperheyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mschipperheyn/subscriptions","organizations_url":"https://api.github.com/users/mschipperheyn/orgs","repos_url":"https://api.github.com/users/mschipperheyn/repos","events_url":"https://api.github.com/users/mschipperheyn/events{/privacy}","received_events_url":"https://api.github.com/users/mschipperheyn/received_events","type":"User","site_admin":false},"created_at":"2018-07-20T14:40:31Z","updated_at":"2018-07-20T14:40:31Z","author_association":"NONE","body":"@doovers nice. But you should put `await customer.$create` etc. That kills the parallel behavior of `Promise.all`. It should imho be\r\n\r\n```\r\n    await Promise.all([\r\n        ...phoneDelta.added.map(async phone => customer.$create('phone', phone, { transaction })),\r\n        ...phoneDelta.changed.map(async phoneData => {\r\n          const phone = customer.phones.find(_phone => _phone.id === phoneData.id);\r\n          return phone.update(phoneData, { transaction });\r\n        }),\r\n        ...phoneDelta.deleted.map(async phone => phone.destroy({ transaction }))\r\n      ]);\r\n```"}}
{"actor":{"display_login":"mschipperheyn"}}