{"action":"opened","issue":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/118","repository_url":"https://api.github.com/repos/Vincit/objection.js","labels_url":"https://api.github.com/repos/Vincit/objection.js/issues/118/labels{/name}","comments_url":"https://api.github.com/repos/Vincit/objection.js/issues/118/comments","events_url":"https://api.github.com/repos/Vincit/objection.js/issues/118/events","html_url":"https://github.com/Vincit/objection.js/issues/118","id":154215674,"number":118,"title":"Upsert trouble","user":{"login":"crdil","id":11871071,"avatar_url":"https://avatars.githubusercontent.com/u/11871071?v=3","gravatar_id":"","url":"https://api.github.com/users/crdil","html_url":"https://github.com/crdil","followers_url":"https://api.github.com/users/crdil/followers","following_url":"https://api.github.com/users/crdil/following{/other_user}","gists_url":"https://api.github.com/users/crdil/gists{/gist_id}","starred_url":"https://api.github.com/users/crdil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crdil/subscriptions","organizations_url":"https://api.github.com/users/crdil/orgs","repos_url":"https://api.github.com/users/crdil/repos","events_url":"https://api.github.com/users/crdil/events{/privacy}","received_events_url":"https://api.github.com/users/crdil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-11T10:59:07Z","updated_at":"2016-05-11T10:59:07Z","closed_at":null,"body":"I'm trying to use the upsert function from the documentation. But I do not understand how this could work.\r\n```\r\nclass MyQueryBuilder extends QueryBuilder {\r\n  upsert(model) {\r\n    if (model.an_id) {\r\n      return this.update(model).where('an_id', model.an_id).returning('an_id');\r\n    }\r\n    else {\r\n      return this.insert(model).returning('an_id');\r\n    }\r\n  }\r\n}\r\n```\r\nSince model.an_id always will exist for me, the insert query will never run.\r\nIs there anyway I can solve this?"}}