{"action":"closed","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/6892","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/6892/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/6892/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/6892/events","html_url":"https://github.com/sequelize/sequelize/issues/6892","id":190474013,"number":6892,"title":"Generate Sequelize query in a string before executing it","user":{"login":"zenithtekla","id":11691367,"avatar_url":"https://avatars.githubusercontent.com/u/11691367?v=3","gravatar_id":"","url":"https://api.github.com/users/zenithtekla","html_url":"https://github.com/zenithtekla","followers_url":"https://api.github.com/users/zenithtekla/followers","following_url":"https://api.github.com/users/zenithtekla/following{/other_user}","gists_url":"https://api.github.com/users/zenithtekla/gists{/gist_id}","starred_url":"https://api.github.com/users/zenithtekla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zenithtekla/subscriptions","organizations_url":"https://api.github.com/users/zenithtekla/orgs","repos_url":"https://api.github.com/users/zenithtekla/repos","events_url":"https://api.github.com/users/zenithtekla/events{/privacy}","received_events_url":"https://api.github.com/users/zenithtekla/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-19T03:39:14Z","updated_at":"2016-11-22T15:43:11Z","closed_at":"2016-11-22T15:43:11Z","body":"To follow up on [previous issue](https://github.com/sequelize/sequelize/issues/6891)\r\nI have defined models. Is there any way for me to get the query string generated for this?\r\n\r\n```js\r\nfunction getlastDossierEagerLoading(req, res, next){\r\n    ECMS_Equipment.findOne({\r\n      where: req.params,\r\n      attributes: ['asset_id', 'model', 'asset_number', 'last_cal', 'schedule', 'next_cal'],\r\n      include: [\r\n        { model: ECMS_Location, attributes: ['desc']},\r\n        { \r\n             model: ECMS_Dossier, \r\n             attributes: ['time_field', 'file_id', 'filename', 'createdAt', 'updatedAt', 'file'], \r\n             limit: 1\r\n        }\r\n      ],\r\n      // limit: [ [ECMS_Dossier, 1] ], problem is the limit option does not support on associated model, resort to include.separate?\r\n      order: [ [{model: ECMS_Dossier}, 'time_field', 'DESC'] ] // orderBy is fine.\r\n    }).then(function(result){\r\n      res.json(result.dataValues);\r\n    }).catch(function(err){res.json(err);});\r\n  }\r\n```\r\n\r\nAssuming I have ECMS_Equipment model, can I have a method like `ECMS_Equipment.queryGenerator()` and that I can throw the same object in there to get the query and modify|tailor|curtail the query string by myself.\r\n\r\n```js\r\nlet generated_query = ECMS_Equipment.queryGenerator({where: req.params, include: []});\r\nlet updated_query = generated_query + 'LIMIT 1';\r\n```\r\n\r\nIdeally, I should have another method so I can invoke the transaction by `ECMS_Equipment.runQuery(updated_query);`\r\n\r\nCan you implement that? Or if implemented, walk me through the usage. Thanks"}}
{"actor":{"display_login":"janmeier"}}