Tuesday, November 13, 2012

[Rails] 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.








--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/eFNgx7qd94AJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate