Has many through

Hi all.
I have models:

has_many :bookings
has_many :projects, :through => :bookings

has_many :bookings
has_many :weeks, :through => :bookings

belongs_to :project
belongs_to :week

Now I want to get all coresponding entries from the bookings and weeks
table filtered by a query.

@bookings = Booking.find_all_by_project_id(params[:id])
=> [#<Booking id: 1, week_id: 47, project_id: 2, hour: 4>, #<Booking id:
2,
week_id: 48, project_id: 2, hour: 7>]

I have tried soething like that:
Week.includes(:bookings).where(‘bookings.week_id = ?’, @bookings).all
#mysql error

How to get that working? Thanks for help.

On 13 November 2012 13:34, Werner [email protected]
wrote:

belongs_to :week
error
Can you explain again what you want to achieve, I do not understand.

Colin

with the project_id you get already all the corresponding bookings ,
right ?
@bookings = Booking.find_all_by_project_id(params[:id])
=> [#<Booking id: 1, week_id: 47, project_id: 2, hour: 4>, #<Booking id:
2,
week_id: 48, project_id: 2, hour: 7>]

and you want the data associated with the week and the project ? right

why don’t you join the tables data uisng .join ?

Le mardi 13 novembre 2012 14:34:08 UTC+1, Werner a crit :

Hallo Erwin.

yes I want the data from week with the id 47 and 48 (in this case)

Am Dienstag, 13. November 2012 15:23:02 UTC+1 schrieb Erwin: