{"action":"opened","issue":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/50","labels_url":"https://api.github.com/repos/Vincit/objection.js/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/Vincit/objection.js/issues/50/comments","events_url":"https://api.github.com/repos/Vincit/objection.js/issues/50/events","html_url":"https://github.com/Vincit/objection.js/issues/50","id":121925409,"number":50,"title":"Insert oneToOne without select","user":{"login":"mitom","id":3754515,"avatar_url":"https://avatars.githubusercontent.com/u/3754515?v=3","gravatar_id":"","url":"https://api.github.com/users/mitom","html_url":"https://github.com/mitom","followers_url":"https://api.github.com/users/mitom/followers","following_url":"https://api.github.com/users/mitom/following{/other_user}","gists_url":"https://api.github.com/users/mitom/gists{/gist_id}","starred_url":"https://api.github.com/users/mitom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitom/subscriptions","organizations_url":"https://api.github.com/users/mitom/orgs","repos_url":"https://api.github.com/users/mitom/repos","events_url":"https://api.github.com/users/mitom/events{/privacy}","received_events_url":"https://api.github.com/users/mitom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-13T15:33:32Z","updated_at":"2015-12-13T15:33:32Z","closed_at":null,"body":"So what I'm trying to achieve is to map a ManyToOne relationship *only* on the One side and I was wondering if (how) would it work? I have these models and they are fine for fetching data, however I am unsure how to about inserting a new review.\r\n\r\n````javascript\r\nclass Review extends Model {\r\n  static get tableName() {\r\n    return 'review';\r\n  } \r\n  static get relationMappings() {\r\n    return {\r\n      movie: {\r\n        relation: Model.OneToOneRelation,\r\n        modelClass: __dirname + '/Movie',\r\n        join: {\r\n          from: 'review.movie',\r\n          to: 'movie.id'\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n````javascript\r\nclass Movie extends Model {\r\n  static get tableName() {\r\n    return 'movie';\r\n  }\r\n}\r\n```\r\n\r\nMy first idea was to simply try \r\n````javascript\r\nvar review = {\r\n  'message': 'foo',\r\n  'movie': 1\r\n};\r\n\r\nReview.query().insert(review).then(...);\r\n```\r\nWhere 1 is an ID for a movie. This told me that `movie` is supposed to be json. I went through the docs and tried changing 1 to `{'#id': 1}`, but then validation failed (I omitted it from the models but obviously they have properties) complaining for missing fields. \r\n\r\nFrom the docs I saw the way it's supposed to work is something like\r\n````javascript\r\nMovie\r\n  .query()\r\n  .where('id', 1)\r\n  .first()\r\n  .then(function (movie) {\r\n    return movie.$relatedQuery('reviews').insert({message: 'foo'});\r\n  });\r\n```\r\n\r\nBut this would require me to write the mapping on the `movie` side as well and do a select first. I'd prefer to just do the insert and trust the id, then catch the error if the foreign key is wrong. Is there any way to do that?"}}