Last active
December 22, 2015 21:59
-
-
Save michaelminter/6265b67d9aa9c8d498c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SELECT `problems`.* FROM `problems` LEFT OUTER JOIN `subject_nodes` ON `subject_nodes`.`id` = `problems`.`subject_node_id` WHERE `problems`.`deleted` = 0 AND (`problems`.`problem_subject_id` = 74 AND `problems`.`public` = 1 AND `problems`.`problem_set_type` IN (1, 2, 4) AND 'IF(problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL, subject_nodes.parent_id, problems.id) IS NOT NULL') | |
WHERE IF(problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL, subject_nodes.parent_id, problems.id) IS NOT NULL | |
WHERE IF(problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL, subject_nodes.parent_id IS NOT NULL, '') | |
WHERE (CASE problems.problem_set_type=4 AND problems.subject_node_id IS NOT NULL THEN subject_nodes.parent_id IS NOT NULL) |
This file contains hidden or 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
scope :public_problems_in_subject, lambda { |problem_subject_id| | |
joins = arel_table.join(SubjectNode.arel_table, Arel::Nodes::OuterJoin).on(SubjectNode.arel_table[:id].eq(arel_table[:subject_node_id])).join_sources | |
query = arel_table[:problem_subject_id].eq(problem_subject_id) | |
.and(arel_table[:public].eq(true)) | |
.and(arel_table[:problem_set_type].in([PROBLEM_TYPE_QUIZ, PROBLEM_TYPE_DIAGNOSTIC, PROBLEM_TYPE_CONCEPT])) | |
.and("(CASE problems.problem_set_type=#{PROBLEM_TYPE_CONCEPT} AND problems.subject_node_id IS NOT NULL THEN subject_nodes.parent_id IS NOT NULL END)") | |
joins(joins).where(query) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment