[Rails] Re: Noob - Associated Tables Find Query

Peter Baldwin
Thu, 12 Jan 2006 16:35:17 -0000

Anyone able to help with this? Assistance would be much appreciated.
Pete


> I''m trying to write a football prediction game.
>
> I have a Matches table and a Predictions table.
> Each Match :has_many Predictions, and each Prediction :belongs_to a
> Match
>
> Each Match has (amongst other things) a Match.match_date field.
> Each Prediction has (amongst other things) a User_id field
>
> I''m trying to get a list of all Predictions a particular User has
made
> which "belong to" Matches for an arbitrary time period (e.g.
"Time.now
> <= now()")
> e.g. All "User 1"''s predictions relating to matches from
last week.
>
> Given that the tables are associated, is it possible to do a single
> .find query stipulating both the Prediction.User_id and the
> Match.match_date, which returns a list of a user''s predictions for
the
> period?