Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created September 16, 2010 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanepiper/5d71389619a71e897530 to your computer and use it in GitHub Desktop.
Save tanepiper/5d71389619a71e897530 to your computer and use it in GitHub Desktop.
this.get('/', function(req, res) {
db.Question.findAll(function(questions){
var total_questions = questions.length;
var output_questions = [];
questions.forEach(function(question) {
question.getTags(function(tags) {
question.tags = tags;
output_questions.push(question);
--total_questions || done();
});
});
function done() {
res.render('questions/index.jade', {
locals: {
title: parent.settings.APP_NAME,
questions: output_questions
}
});
}
});
});
db.Question.findAll({includeAssociated: true}, function(questions) {
/** Object would contain:
question = {}
question.comments = []
question.tags = []
question.user = {}
*/
db.Question.findAll(function(questions) {
Sequelize.chainQueries([
{getTags: questions}, {getUser: questions}, {getComments: questions}
], function(questions_with_extra_data) {
// We can now do tasty stuff in here like render our view
})
17 Sep 00:16:14 - 'Executing the query: SELECT * FROM Questions'
17 Sep 00:16:14 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=2'
17 Sep 00:16:14 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=1'
17 Sep 00:16:14 - 'Executing the query: SELECT * FROM Tags WHERE id IN (1,2,3)'
17 Sep 00:16:14 - 'Executing the query: SELECT * FROM Tags WHERE id IN (4,5,6)'
17 Sep 00:16:16 - 'Executing the query: SELECT * FROM Questions'
17 Sep 00:16:16 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=1'
17 Sep 00:16:16 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=2'
17 Sep 00:16:16 - 'Executing the query: SELECT * FROM Tags WHERE id IN (1,2,3)'
17 Sep 00:16:16 - 'Executing the query: SELECT * FROM Tags WHERE id IN (4,5,6)'
17 Sep 00:16:18 - 'Executing the query: SELECT * FROM Questions'
17 Sep 00:16:18 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=1'
17 Sep 00:16:18 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=2'
17 Sep 00:16:18 - 'Executing the query: SELECT * FROM Tags WHERE id IN (1,2,3)'
17 Sep 00:16:18 - 'Executing the query: SELECT * FROM Tags WHERE id IN (4,5,6)'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM Questions'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=2'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=1'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM Tags WHERE id IN (4,5,6)'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM Tags WHERE id IN (1,2,3)'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM Questions'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=2'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=1'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM Tags WHERE id IN (1,2,3)'
17 Sep 00:16:19 - 'Executing the query: SELECT * FROM Tags WHERE id IN (4,5,6)'
17 Sep 00:16:20 - 'Executing the query: SELECT * FROM Questions'
17 Sep 00:16:20 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=2'
17 Sep 00:16:20 - 'Executing the query: SELECT * FROM QuestionsTags WHERE questionId=1'
17 Sep 00:16:20 - 'Executing the query: SELECT * FROM Tags WHERE id IN (4,5,6)'
17 Sep 00:16:20 - 'Executing the query: SELECT * FROM Tags WHERE id IN (1,2,3)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment