[Rails] Re: Re: Noob - Associated Tables Find Query

Pete Baldwin
Thu, 12 Jan 2006 23:39:00 -0000

Jan and Chris, I really appreciate your responses.

I went with Chris''s alternatives, and have ended up with the following

class User < ActiveRecord::Base
	has_many :predictions, :include => :matches
end

class Match < ActiveRecord::Base
	has_many :predictions
end

class Prediction < ActiveRecord::Base
	belongs_to :user
	belongs_to :match
end

---controller---
@user = User.find(session[:user_id])
@cutoff_date = Time.new


@oldpredictions = @user.predictions.find(:all, :joins => "matches",
:conditions => ["predictions.match_id = match.id and match.match_date
<=
?", @cutoff_date])

----

But its giving me the following error...

Mysql::Error: Unknown table ''predictions'' in where clause:
SELECT * FROM
predictions  matches WHERE (predictions.user_id = 2 AND
(predictions.match_id = match.id and match.match_date <= ''2006-01-12
18:34:14''))

and if I load up the console, and go

@user = User.find(1)
@user.predictions

it gives me the following error

ActiveRecord::ConfigurationError: Association was not found; perhaps you
misspelled it?  You specified :include => :matches

Is there something wrong with the models?

Cheers again,