Created
June 26, 2011 19:17
-
-
Save DCarper/1047879 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
| class Bracket < ActiveRecord::Base | |
| has_many :guesses | |
| has_many :memberships | |
| has_many :comments, :through => :memberships | |
| # Class Guess < BracketInfo | |
| named_scope :recently_updated, :include => [:comments, :guesses], :conditions => ['bracket_infos.created_at > ? OR comments.created_at > ?', Chronic.parse("Yesterday at 5 am"), Chronic.parse("Yesterday at 5 am")] | |
| # Good # Bracket.recently_updated => [...] | |
| # Good # Bracket.recently_updated.each { |bracket| puts bracket.to_s } | |
| # Bad # Bracket.recently_updated.first | |
| # Bad # Bracket.recently_updated.last | |
| # => | |
| ## ActiveRecord::StatementInvalid Exception: Mysql::Error: Column 'status' in on clause is ambiguous: SELECT DISTINCT `brackets`.id FROM `brackets` | |
| OUTER JOIN `bracket_infos` ON bracket_infos.bracket_id = brackets.id AND (`bracket_infos`.`type` = 'Guess' ) LEFT OUTER JOIN `memberships` ON | |
| (`brackets`.`id` = `memberships`.`app_id` AND `memberships`.`app_type` = 'Bracket') LEFT OUTER JOIN `comments` | |
| ON (`comments`.`commentable_id` = `memberships`.`id` AND `comments`.`commentable_type` = 'Membership') AND status = 'Member' OR | |
| type = 'Ownership' WHERE (bracket_infos.created_at > '2011-06-25 05:00:00' OR comments.created_at > '2011-06-25 05:00:00') LIMIT 1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment