{"action":"created","issue":{"url":"https://api.github.com/repos/adonisjs/adonis-lucid/issues/290","repository_url":"https://api.github.com/repos/adonisjs/adonis-lucid","labels_url":"https://api.github.com/repos/adonisjs/adonis-lucid/issues/290/labels{/name}","comments_url":"https://api.github.com/repos/adonisjs/adonis-lucid/issues/290/comments","events_url":"https://api.github.com/repos/adonisjs/adonis-lucid/issues/290/events","html_url":"https://github.com/adonisjs/adonis-lucid/issues/290","id":292196777,"number":290,"title":"\"with\" for relation with custom fk","user":{"login":"urgotto","id":5137606,"avatar_url":"https://avatars1.githubusercontent.com/u/5137606?v=4","gravatar_id":"","url":"https://api.github.com/users/urgotto","html_url":"https://github.com/urgotto","followers_url":"https://api.github.com/users/urgotto/followers","following_url":"https://api.github.com/users/urgotto/following{/other_user}","gists_url":"https://api.github.com/users/urgotto/gists{/gist_id}","starred_url":"https://api.github.com/users/urgotto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urgotto/subscriptions","organizations_url":"https://api.github.com/users/urgotto/orgs","repos_url":"https://api.github.com/users/urgotto/repos","events_url":"https://api.github.com/users/urgotto/events{/privacy}","received_events_url":"https://api.github.com/users/urgotto/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"thetutlage","id":1706381,"avatar_url":"https://avatars1.githubusercontent.com/u/1706381?v=4","gravatar_id":"","url":"https://api.github.com/users/thetutlage","html_url":"https://github.com/thetutlage","followers_url":"https://api.github.com/users/thetutlage/followers","following_url":"https://api.github.com/users/thetutlage/following{/other_user}","gists_url":"https://api.github.com/users/thetutlage/gists{/gist_id}","starred_url":"https://api.github.com/users/thetutlage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thetutlage/subscriptions","organizations_url":"https://api.github.com/users/thetutlage/orgs","repos_url":"https://api.github.com/users/thetutlage/repos","events_url":"https://api.github.com/users/thetutlage/events{/privacy}","received_events_url":"https://api.github.com/users/thetutlage/received_events","type":"User","site_admin":false},"assignees":[{"login":"thetutlage","id":1706381,"avatar_url":"https://avatars1.githubusercontent.com/u/1706381?v=4","gravatar_id":"","url":"https://api.github.com/users/thetutlage","html_url":"https://github.com/thetutlage","followers_url":"https://api.github.com/users/thetutlage/followers","following_url":"https://api.github.com/users/thetutlage/following{/other_user}","gists_url":"https://api.github.com/users/thetutlage/gists{/gist_id}","starred_url":"https://api.github.com/users/thetutlage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thetutlage/subscriptions","organizations_url":"https://api.github.com/users/thetutlage/orgs","repos_url":"https://api.github.com/users/thetutlage/repos","events_url":"https://api.github.com/users/thetutlage/events{/privacy}","received_events_url":"https://api.github.com/users/thetutlage/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2018-01-28T11:15:46Z","updated_at":"2018-02-19T10:53:10Z","closed_at":null,"author_association":"NONE","body":"Hi guys, i have a strange behavior when use \"with\" method on one of my models in  @adonisjs/lucid@4.1.3 \r\n\r\nModels:\r\n\r\n```js\r\n// Slider {id, name...}\r\n'use strict'\r\n\r\nconst Model = use('Model')\r\n\r\nclass Slider extends Model {\r\n  book () {\r\n    return this.belongsTo('App/Models/Book')\r\n  }\r\n\r\n  imageLeft () {\r\n    return this.hasOne('App/Models/SystemFile', 'id', 'attachment_id')\r\n      .where('field', 'image_left')\r\n      .where('attachment_type', 'Slider')\r\n  }\r\n\r\n  imageRight () {\r\n    return this.hasOne('App/Models/SystemFile', 'id', 'attachment_id')\r\n      .where('field', 'image_right')\r\n      .where('attachment_type', 'Slider')\r\n  }\r\n}\r\n\r\nmodule.exports = Slider\r\n```\r\n\r\n```js\r\n// Book {id, name...}\r\n'use strict'\r\n\r\nconst Model = use('Model')\r\n\r\nclass Book extends Model {\r\n  sliders () {\r\n    return this.hasMany('App/Models/Slider')\r\n  }\r\n  image () {\r\n    return this.hasOne('App/Models/SystemFile', 'id', 'attachment_id')\r\n      .where('field', 'image')\r\n      .where('attachment_type', 'Book')\r\n  }\r\n}\r\n\r\nmodule.exports = Book\r\n\r\n```\r\n\r\n```js\r\n// SystemFile {id, path, field, attachment_id, attachment_type...}\r\n'use strict'\r\n\r\nconst Model = use('Model')\r\nconst Config = use('Config')\r\n\r\nclass SystemFile extends Model {\r\n}\r\n\r\nmodule.exports = SystemFile\r\n```\r\n\r\nand controllers code\r\n\r\n```js\r\nlet sliders = await Slider.query()\r\n  .with('imageLeft').with('imageRight').with('book.image')\r\n  .fetch()\r\nconsole.log(sliders.toJSON())\r\n```\r\n\r\nreturn me next \r\n\r\n```js\r\n[ {\r\n  id: 1,\r\n  created_at: '2018-01-08 10:30:03',\r\n  updated_at: '2018-01-08 10:30:03',\r\n  imageLeft: null,\r\n  imageRight: null,\r\n  book: \r\n  {\r\n    id: 1,\r\n    created_at: '2017-10-11 19:37:49',\r\n    updated_at: '2018-01-08 11:31:38',\r\n    version: '0.1.0',\r\n    title: 'Test 1',\r\n    description: 'First test book',\r\n    slug: 'book1',\r\n    image: null \r\n  }\r\n}, { \r\n  id: 2,\r\n  created_at: '2018-01-08 12:33:03',\r\n  updated_at: '2018-01-08 12:36:48',\r\n  imageLeft: null,\r\n  imageRight: null,\r\n  book: \r\n  {\r\n    id: 2,\r\n    created_at: '2018-01-08 12:27:21',\r\n    updated_at: '2018-01-08 12:30:13',\r\n    version: '0.1.0',\r\n    title: 'Test 2',\r\n    description: 'Second test book',\r\n    slug: 'test2book',\r\n    image: null \r\n  }\r\n}...]\r\n```\r\n\r\nRelation 'Book' loaded without any problems, but relations 'Slider.imageLeft', 'Slider.imageRight', 'Book.image' loaded as null. If i write something like:\r\n\r\n```js\r\nlet sliders = await Slider.query().fetch()\r\nfor (let slider of sliders.rows) {\r\n  await slider.loadMany(['imageLeft', 'imageRight', 'book.image'])\r\n}\r\nconsole.log(sliders.toJSON())\r\n```\r\n\r\ni will get \r\n\r\n```js\r\n[ { \r\n  id: 1,\r\n  book_id: 1,\r\n  created_at: '2018-01-08 10:30:03',\r\n  updated_at: '2018-01-08 10:30:03',\r\n  imageLeft: \r\n  {\r\n    id: 16,\r\n    path: '5a6c82893878b621516471.jpg',\r\n    file_name: 'slide_01.jpg',\r\n    file_size: 677612,\r\n    content_type: 'image/jpeg',\r\n    title: null,\r\n    description: null,\r\n    field: 'image_left',\r\n    attachment_id: '1',\r\n    attachment_type: 'Slider',\r\n    is_public: 1,\r\n    sort_order: 16,\r\n    created_at: '2018-01-27 13:45:45',\r\n    updated_at: '2018-01-27 13:45:50',\r\n  },\r\n  imageRight: \r\n  {\r\n    id: 17,\r\n    path: '5a6c828cca097558776102.jpg',\r\n    file_name: 'slide_02.jpg',\r\n    file_size: 677612,\r\n    content_type: 'image/jpeg',\r\n    title: null,\r\n    description: null,\r\n    field: 'image_right',\r\n    attachment_id: '1',\r\n    attachment_type: 'Slider',\r\n    is_public: 1,\r\n    sort_order: 17,\r\n    created_at: '2018-01-27 13:45:48',\r\n    updated_at: '2018-01-27 13:45:50',\r\n  },\r\n  book: \r\n  {\r\n    id: 1,\r\n    created_at: '2017-10-11 19:37:49',\r\n    updated_at: '2018-01-08 11:31:38',\r\n    version: '0.1.0',\r\n    title: 'Test 1',\r\n    description: 'First test book',\r\n    slug: 'book1',\r\n    image: null \r\n  }\r\n}...]\r\n\r\n```\r\n\r\nIn this way relations 'Slider.imageLeft', 'Slider.imageRight' and 'Slide.book' will be loaded but 'Slider.book.image' is still missing. \r\n\r\nI`m not sure, is it important but i have innodb foreigk keys for 'slider.book' only\r\n\r\n```js\r\ntable.foreign('book_id', 'sliders_ibfk_1')\r\n  .references('id').inTable('books')\r\n  .onUpdate('NO ACTION').onDelete('CASCADE');\r\n``` \r\n\r\nCan any one help me to figure out this issue?\r\nPS: In 3.x version this code was work as a charm."},"comment":{"url":"https://api.github.com/repos/adonisjs/adonis-lucid/issues/comments/366654221","html_url":"https://github.com/adonisjs/adonis-lucid/issues/290#issuecomment-366654221","issue_url":"https://api.github.com/repos/adonisjs/adonis-lucid/issues/290","id":366654221,"user":{"login":"urgotto","id":5137606,"avatar_url":"https://avatars1.githubusercontent.com/u/5137606?v=4","gravatar_id":"","url":"https://api.github.com/users/urgotto","html_url":"https://github.com/urgotto","followers_url":"https://api.github.com/users/urgotto/followers","following_url":"https://api.github.com/users/urgotto/following{/other_user}","gists_url":"https://api.github.com/users/urgotto/gists{/gist_id}","starred_url":"https://api.github.com/users/urgotto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urgotto/subscriptions","organizations_url":"https://api.github.com/users/urgotto/orgs","repos_url":"https://api.github.com/users/urgotto/repos","events_url":"https://api.github.com/users/urgotto/events{/privacy}","received_events_url":"https://api.github.com/users/urgotto/received_events","type":"User","site_admin":false},"created_at":"2018-02-19T10:53:10Z","updated_at":"2018-02-19T10:53:10Z","author_association":"NONE","body":"I found a problem, it wasn`t server. My external system (it create a modify system_files table) use varchar for key field (attachment_id). Function \"load\" in lucid work well with it, but \"with\" function did not."}}
{"actor":{"display_login":"urgotto"}}