{"action":"created","issue":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/957","repository_url":"https://api.github.com/repos/Vincit/objection.js","labels_url":"https://api.github.com/repos/Vincit/objection.js/issues/957/labels{/name}","comments_url":"https://api.github.com/repos/Vincit/objection.js/issues/957/comments","events_url":"https://api.github.com/repos/Vincit/objection.js/issues/957/events","html_url":"https://github.com/Vincit/objection.js/issues/957","id":331611548,"node_id":"MDU6SXNzdWUzMzE2MTE1NDg=","number":957,"title":"$afterUpdate does not contain enough data when using $relatedQuery","user":{"login":"bodinsamuel","id":1637651,"node_id":"MDQ6VXNlcjE2Mzc2NTE=","avatar_url":"https://avatars1.githubusercontent.com/u/1637651?v=4","gravatar_id":"","url":"https://api.github.com/users/bodinsamuel","html_url":"https://github.com/bodinsamuel","followers_url":"https://api.github.com/users/bodinsamuel/followers","following_url":"https://api.github.com/users/bodinsamuel/following{/other_user}","gists_url":"https://api.github.com/users/bodinsamuel/gists{/gist_id}","starred_url":"https://api.github.com/users/bodinsamuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodinsamuel/subscriptions","organizations_url":"https://api.github.com/users/bodinsamuel/orgs","repos_url":"https://api.github.com/users/bodinsamuel/repos","events_url":"https://api.github.com/users/bodinsamuel/events{/privacy}","received_events_url":"https://api.github.com/users/bodinsamuel/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-12T14:25:39Z","updated_at":"2018-06-12T17:39:53Z","closed_at":"2018-06-12T15:30:01Z","author_association":"NONE","body":"Hi,\r\n\r\nI'm using objectionsjs for about a month (so I may be missing some tricks).\r\nBut when I use $relatedQuery to link a model to another, $afterUpdate is triggered correctly but does not contain all the information, even if I'm pretty sure objection has it somewhere.\r\n\r\nExample\r\n```javascript\r\nconst idToLink = 1234;\r\nconst one = await One.query().where({ id: 1 }).first();\r\none.$relatedQuery('two').relate(idToLink);\r\n\r\n## trigger => one.$afterUpdate(queryContext);\r\nqueryContext = { patch: true };\r\nthis = { two_id: 1234 }; \r\n```\r\n\r\nI don't know it's clear, but I fetched model `one` and link a belongTo relation `two`\r\nwhen the `one.$afterUpdate` is triggered, the queryContext contain nothing usefull and `this` contain only what changed. The model should be a copy of the one queried I suppose.\r\nIn my case, I'm executing sensitive task in afterUpdate, if this afterUpdate does not contain the ID, I can not keep my task up to date :/ \r\n\r\nMaybe I'm also doing something wrong, but I'm following the doc.\r\n\r\nThanks :)\r\n"},"comment":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/comments/396673798","html_url":"https://github.com/Vincit/objection.js/issues/957#issuecomment-396673798","issue_url":"https://api.github.com/repos/Vincit/objection.js/issues/957","id":396673798,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NjY3Mzc5OA==","user":{"login":"bodinsamuel","id":1637651,"node_id":"MDQ6VXNlcjE2Mzc2NTE=","avatar_url":"https://avatars1.githubusercontent.com/u/1637651?v=4","gravatar_id":"","url":"https://api.github.com/users/bodinsamuel","html_url":"https://github.com/bodinsamuel","followers_url":"https://api.github.com/users/bodinsamuel/followers","following_url":"https://api.github.com/users/bodinsamuel/following{/other_user}","gists_url":"https://api.github.com/users/bodinsamuel/gists{/gist_id}","starred_url":"https://api.github.com/users/bodinsamuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodinsamuel/subscriptions","organizations_url":"https://api.github.com/users/bodinsamuel/orgs","repos_url":"https://api.github.com/users/bodinsamuel/repos","events_url":"https://api.github.com/users/bodinsamuel/events{/privacy}","received_events_url":"https://api.github.com/users/bodinsamuel/received_events","type":"User","site_admin":false},"created_at":"2018-06-12T17:39:53Z","updated_at":"2018-06-12T17:39:53Z","author_association":"NONE","body":"Thanks for the quick answer, but this is not true :/\r\nHere is the full repro (with a PG, you can change the conf) maybe you will understand it better :)\r\n```javascript\r\n# repro.js\r\nconst knex = require('knex');\r\nvar { Model } = require('objection');\r\n\r\n\r\nclass Test1 extends Model {\r\n  static tableName() {\r\n    return 'Test1';\r\n  }\r\n}\r\nclass Test2 extends Model {\r\n  static tableName() {\r\n    return 'Test2';\r\n  }\r\n  static get relationMappings() {\r\n    return {\r\n      test: {\r\n        relation: Model.BelongsToOneRelation,\r\n        modelClass: Test1,\r\n        join: {\r\n          from: 'Test1.id',\r\n          to: 'Test2.test1Id',\r\n        },\r\n      },\r\n    };\r\n  }\r\n\r\n  $afterUpdate(opt) {\r\n    console.log('------- this will print undefined =>', opt.old);\r\n  }\r\n}\r\n\r\nconst connection = knex({\r\n  client: 'postgresql',\r\n  debug: true,\r\n  connection: {\r\n    host: 'localhost',\r\n    user: 'api',\r\n    password: 'api1234',\r\n    database: 'api',\r\n    port: 5432,\r\n  },\r\n  // connection: 'postgresql://api:blabla@localhost:5432/api',\r\n  migrations: {\r\n    tableName: 'knex_migrations',\r\n    directory: './migrations',\r\n  },\r\n  seeds: {\r\n    tableName: 'knex_seeds',\r\n    directory: './seeds',\r\n  },\r\n});\r\nModel.knex(connection);\r\n\r\nconst run = async function() {\r\n  const hasTable1 = await connection.schema.hasTable('Test1');\r\n  if (!hasTable1) {\r\n    await connection.schema.createTable('Test1', (table) => {\r\n      table\r\n        .increments('id')\r\n        .unsigned()\r\n        .primary();\r\n    });\r\n  }\r\n  const hasTable2 = await connection.schema.hasTable('Test2');\r\n  if (!hasTable2) {\r\n    await connection.schema.createTable('Test2', (table) => {\r\n      table\r\n        .increments('id')\r\n        .unsigned()\r\n        .primary();\r\n      table\r\n        .integer('test1Id')\r\n        .unsigned()\r\n        .references('id')\r\n        .inTable('Test1')\r\n        .nullable();\r\n    });\r\n  }\r\n\r\n  const m1 = await Test1.query().insert({}).returning('*');\r\n  const m2 = await Test2.query().insert({}).returning('*');\r\n\r\n  const m3 = await m2.$relatedQuery('test').relate(m1.id);\r\n};\r\n\r\nrun();\r\n```\r\n\r\n```bash\r\nnode repro.js\r\n```"}}
{"actor":{"display_login":"bodinsamuel"}}