this simple question new sql , rails not able find answer. lets have competition model each competition having many questions. ie competition has_many questions. question belongs competition
competition has column "status" possible values "open" , "closed"
i want display questions user (irrespective of competition belong to) competition still "open"
i looking not syntactically correct. question.where(competition.status="open")
this query want:
question.joins(:competition).where('competitions.status = ?', 'open') but make method inside questionmodel like
class question < activerecord::base def self.from_opened_competitions joins(:competition).where('competitions.status = ?', 'open') end end
Comments
Post a Comment