I have an outings table, which basically holds some information about an 'outing'. These outings then have crews, which have users (through crew_users)
Just as a note, outings have many crews, so there's an outing_id in the crews table
Now, I need to find the user's next outing, as in the first outing where outing.start_time > Time.now
I've got this in my user.rb model:
has_many :crew_users
has_many :crews, :through => :crew_users
has_many :outings, :through => :crews
And when I try to do this:
>> Users.find(1).outings
I get this error:
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'crews.user_id'
in 'where clause': SELECT `outings`.* FROM `outings` INNER JOIN `crews` ON
`outings`.id = `crews`.outing_id WHERE ((`crews`.user_id = 1))
Anyone any ideas? Like I said, my goal is to get the user's next outing from the current time so there may very well be a much better to go about this!