mercredi 15 juillet 2015

Get all fields from activerecord, filtered by a column in a different table

This is a simple question but as I am new with sql and Rails I am not able to find the answer. Lets say I have a Competition model with each competition having many questions. ie Competition has_many Questions. Question belongs to Competition

Competition has a column "status" with possible values "open" and "closed"

I want to display all questions to the user (irrespective of which competition they belong to) whose competition is still "open"

I am looking for something like this but this is not syntactically correct. Question.where(competition.status="open")

Aucun commentaire:

Enregistrer un commentaire