{"action":"created","issue":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/35","labels_url":"https://api.github.com/repos/Vincit/objection.js/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/Vincit/objection.js/issues/35/comments","events_url":"https://api.github.com/repos/Vincit/objection.js/issues/35/events","html_url":"https://github.com/Vincit/objection.js/issues/35","id":107808010,"number":35,"title":"Eager fetch is resulting in empty array","user":{"login":"jsumners","id":321201,"avatar_url":"https://avatars.githubusercontent.com/u/321201?v=3","gravatar_id":"","url":"https://api.github.com/users/jsumners","html_url":"https://github.com/jsumners","followers_url":"https://api.github.com/users/jsumners/followers","following_url":"https://api.github.com/users/jsumners/following{/other_user}","gists_url":"https://api.github.com/users/jsumners/gists{/gist_id}","starred_url":"https://api.github.com/users/jsumners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsumners/subscriptions","organizations_url":"https://api.github.com/users/jsumners/orgs","repos_url":"https://api.github.com/users/jsumners/repos","events_url":"https://api.github.com/users/jsumners/events{/privacy}","received_events_url":"https://api.github.com/users/jsumners/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-22T21:37:18Z","updated_at":"2015-09-22T22:47:33Z","closed_at":null,"body":"I have three tables: `people`, `roles`, `person_roles`. I have defined many-to-many relationships on each of the models for `people` (`person`) and `roles` (`role`). As a test, I issue the following query:\r\n\r\n```javascript\r\nmodels.Person\r\n  .query()\r\n  .eager('roles')\r\n  .where({id: 1})\r\n  .then(function (people) {\r\n    console.log(people[0]);\r\n    knex.destroy();\r\n  })\r\n  .catch(function (err) {\r\n    console.error(err);\r\n    knex.destroy();\r\n  });\r\n```\r\n\r\nThe result of which is the details from the `people` table for that person, but with a `roles` attribute set to `[]`. It looks to me like the issue is happening on [line 94](https://github.com/Vincit/objection.js/blob/master/lib/relations/ManyToManyRelation.js#L94) of `ManyToManyRelation.js`. The result of that line is an object with one property. The name of that property is \"undefined\". But the next access of that object is:\r\n\r\n```javascript\r\nowner[self.name] = relatedByOwnerId[owner[self.ownerProp]] || [];\r\n```\r\n\r\nNothing in the bracket resolves to \"undefined\", so the result is `[]`.\r\n\r\n![2015-09-22_17-26-20](https://cloud.githubusercontent.com/assets/321201/10032113/1c718c58-614f-11e5-892f-3512ed7aa8b2.png)"},"comment":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/comments/142442724","html_url":"https://github.com/Vincit/objection.js/issues/35#issuecomment-142442724","issue_url":"https://api.github.com/repos/Vincit/objection.js/issues/35","id":142442724,"user":{"login":"koskimas","id":846508,"avatar_url":"https://avatars.githubusercontent.com/u/846508?v=3","gravatar_id":"","url":"https://api.github.com/users/koskimas","html_url":"https://github.com/koskimas","followers_url":"https://api.github.com/users/koskimas/followers","following_url":"https://api.github.com/users/koskimas/following{/other_user}","gists_url":"https://api.github.com/users/koskimas/gists{/gist_id}","starred_url":"https://api.github.com/users/koskimas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koskimas/subscriptions","organizations_url":"https://api.github.com/users/koskimas/orgs","repos_url":"https://api.github.com/users/koskimas/repos","events_url":"https://api.github.com/users/koskimas/events{/privacy}","received_events_url":"https://api.github.com/users/koskimas/received_events","type":"User","site_admin":false},"created_at":"2015-09-22T22:47:33Z","updated_at":"2015-09-22T22:47:33Z","body":"By the way: you don't need the lines\r\n\r\n```js\r\nBaseModel.prototype = Object.create(Model.prototype);\r\nBaseModel.prototype.constructor = BaseModel;\r\n```\r\n\r\nModel.extend does this for you."}}