{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/778","labels_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/778/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/778/comments","events_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/778/events","html_url":"https://github.com/tgriesser/bookshelf/issues/778","id":86772356,"number":778,"title":"BelongsTo models .related() function not querying as expected","user":{"login":"ezra-quemuel","id":5275143,"avatar_url":"https://avatars.githubusercontent.com/u/5275143?v=3","gravatar_id":"","url":"https://api.github.com/users/ezra-quemuel","html_url":"https://github.com/ezra-quemuel","followers_url":"https://api.github.com/users/ezra-quemuel/followers","following_url":"https://api.github.com/users/ezra-quemuel/following{/other_user}","gists_url":"https://api.github.com/users/ezra-quemuel/gists{/gist_id}","starred_url":"https://api.github.com/users/ezra-quemuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezra-quemuel/subscriptions","organizations_url":"https://api.github.com/users/ezra-quemuel/orgs","repos_url":"https://api.github.com/users/ezra-quemuel/repos","events_url":"https://api.github.com/users/ezra-quemuel/events{/privacy}","received_events_url":"https://api.github.com/users/ezra-quemuel/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tgriesser/bookshelf/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-06-09T23:47:40Z","updated_at":"2015-06-14T12:42:12Z","closed_at":null,"body":"I have 2 models, defined with belongsTo and inversely hasMany on the other model.\r\nTarget -> belongsTo -> Dataset\r\nDataset -> hasMany -> Target\r\n\r\nWhen calling the related() function on the belongsTo target such as:\r\nthis.related(\"dataset\").fetch()\r\nit runs the following query in postgresql:\r\n\r\n```sql\r\nselect \"dataset\".* from \"dataset\" where \"dataset\".\"name\" = $1 and \"dataset\".\"description\" is null and \"dataset\".\"status\" = $2 and \"dataset\".\"labels\" = $3 and \"dataset\".\"created_at\" = $4 and \"dataset\".\"modified_at\" = $5 and \"dataset\".\"created_by\" = $6 and \"dataset\".\"modified_by\" = $7 and \"dataset\".\"owner_id\" = $8 and \"dataset\".\"id\" = $9 and \"dataset\".\"metadata\" is null and \"dataset\".\"id\" = $10 limit $11\r\n```\r\n\r\n\r\nThis throws an error because \"dataset\".\"labels\" is a JSON column.\r\nIf I query using a `forge({id: someId}).fetch()` it runs a select only using the 'id' (desired result)\r\n\r\nAny ideas on this?\r\n\r\nUPDATE:\r\nThis only seems to happen when I pass this specific withRelated option to \r\n\r\n```js\r\nthis.related(\"dataset\").fetch()\r\n\r\nself.related(\"dataset\").fetch({\r\n            withRelated: [{\r\n                'schemas': function (qb) {\r\n                    qb.limit(1);\r\n                    qb.orderBy('modified_at', 'DESC');\r\n                }\r\n            }]\r\n        })\r\n```"},"comment":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/comments/111822654","html_url":"https://github.com/tgriesser/bookshelf/issues/778#issuecomment-111822654","issue_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/778","id":111822654,"user":{"login":"rhys-vdw","id":822105,"avatar_url":"https://avatars.githubusercontent.com/u/822105?v=3","gravatar_id":"","url":"https://api.github.com/users/rhys-vdw","html_url":"https://github.com/rhys-vdw","followers_url":"https://api.github.com/users/rhys-vdw/followers","following_url":"https://api.github.com/users/rhys-vdw/following{/other_user}","gists_url":"https://api.github.com/users/rhys-vdw/gists{/gist_id}","starred_url":"https://api.github.com/users/rhys-vdw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhys-vdw/subscriptions","organizations_url":"https://api.github.com/users/rhys-vdw/orgs","repos_url":"https://api.github.com/users/rhys-vdw/repos","events_url":"https://api.github.com/users/rhys-vdw/events{/privacy}","received_events_url":"https://api.github.com/users/rhys-vdw/received_events","type":"User","site_admin":false},"created_at":"2015-06-14T12:42:12Z","updated_at":"2015-06-14T12:42:12Z","body":"I'm going to close this as a duplicate of #550. We can discuss the issue there. "}}