-
-
Save tanepiper/5d71389619a71e897530 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.Question.findAll({includeAssociated: true}, function(questions) { | |
/** Object would contain: | |
question = {} | |
question.comments = [] | |
question.tags = [] | |
question.user = {} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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