{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3176","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3176/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3176/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3176/events","html_url":"https://github.com/Automattic/mongoose/issues/3176","id":95849467,"number":3176,"title":"CustomQuery with Query#toConstructor returns lean documents","user":{"login":"QuantumKing","id":235305,"avatar_url":"https://avatars.githubusercontent.com/u/235305?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantumKing","html_url":"https://github.com/QuantumKing","followers_url":"https://api.github.com/users/QuantumKing/followers","following_url":"https://api.github.com/users/QuantumKing/following{/other_user}","gists_url":"https://api.github.com/users/QuantumKing/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantumKing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantumKing/subscriptions","organizations_url":"https://api.github.com/users/QuantumKing/orgs","repos_url":"https://api.github.com/users/QuantumKing/repos","events_url":"https://api.github.com/users/QuantumKing/events{/privacy}","received_events_url":"https://api.github.com/users/QuantumKing/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/50","html_url":"https://github.com/Automattic/mongoose/milestones/4.0.9","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/50/labels","id":1211321,"number":50,"title":"4.0.9","description":"","creator":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"open_issues":20,"closed_issues":0,"state":"open","created_at":"2015-07-16T14:37:02Z","updated_at":"2015-07-20T18:34:50Z","due_on":"2015-07-31T04:00:00Z","closed_at":null},"comments":2,"created_at":"2015-07-18T18:44:09Z","updated_at":"2015-07-20T20:09:02Z","closed_at":null,"body":"I have a custom query\r\n\r\n```js\r\nvar _PermissionsQuery;\r\nschema.statics.PermissionsQuery = function() {\r\n  if (!_PermissionsQuery) {\r\n    _PermissionsQuery = this.where({}).toConstructor();\r\n  }\r\n  return _PermissionsQuery();\r\n};\r\n```\r\nbut whenever I use it after a lean(), it continues to return lean documents:\r\n\r\n```js\r\nmodel.PermissionsQuery().lean().exec(function(err, result) {\r\n  console.log(result.save); // prints undefined\r\n\r\n  model.PermissionsQuery().exec(function(err, result) {\r\n    console.log(result.save); // prints undefined\r\n  });\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/123014242","html_url":"https://github.com/Automattic/mongoose/issues/3176#issuecomment-123014242","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3176","id":123014242,"user":{"login":"QuantumKing","id":235305,"avatar_url":"https://avatars.githubusercontent.com/u/235305?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantumKing","html_url":"https://github.com/QuantumKing","followers_url":"https://api.github.com/users/QuantumKing/followers","following_url":"https://api.github.com/users/QuantumKing/following{/other_user}","gists_url":"https://api.github.com/users/QuantumKing/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantumKing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantumKing/subscriptions","organizations_url":"https://api.github.com/users/QuantumKing/orgs","repos_url":"https://api.github.com/users/QuantumKing/repos","events_url":"https://api.github.com/users/QuantumKing/events{/privacy}","received_events_url":"https://api.github.com/users/QuantumKing/received_events","type":"User","site_admin":false},"created_at":"2015-07-20T20:09:02Z","updated_at":"2015-07-20T20:09:02Z","body":"Also, `populate` ruins the CustomQuery's reusability"}}