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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 13 November 2012 13:34, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 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 > errorCan you explain again what you want to achieve, I do not understand. Colin> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
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 :> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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/-/WOVjhWDahfYJ. For more options, visit https://groups.google.com/groups/opt_out.
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:> > 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 : >> >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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/-/a_MPjy7H3NoJ. For more options, visit https://groups.google.com/groups/opt_out.
On 13 November 2012 13:56, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi Colin.Please remember to reply to the list and please don''t top post, it makes it difficult to follow the thread. Insert your reply inline at appropriate points in the previous message. Thanks.> > 1. I ask for entries in booking with a certain project_id > @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>]So you know how to do that ok?> > 2. Get the values from the table week which have the week_id from the 1 (47, > 48)Sorry, still don''t understand what that is supposed to mean. I presume that you mean records rather than values and the table weeks rather than weeks. So you want to get the records from the table weeks. But that table does not have a column week_id, just id and no idea what you mean by "from the 1(47,48)" Colin> > But how to I ask that? > > > Am Dienstag, 13. November 2012 14:44:09 UTC+1 schrieb Colin Law: >> >> On 13 November 2012 13:34, Werner <webagent...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> > 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 >> >> Can you explain again what you want to achieve, I do not understand. >> >> Colin >> >> > >> > 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 rubyonra...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > To unsubscribe from this group, send email to >> > rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > 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. >> > >> >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 13 November 2012 15:15, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 13 November 2012 13:56, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> Hi Colin. > > Please remember to reply to the list and please don''t top post, it > makes it difficult to follow the thread. Insert your reply inline at > appropriate points in the previous message. Thanks. > >> >> 1. I ask for entries in booking with a certain project_id >> @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>] > > So you know how to do that ok? > >> >> 2. Get the values from the table week which have the week_id from the 1 (47, >> 48) > > Sorry, still don''t understand what that is supposed to mean. I > presume that you mean records rather than values and the table weeks > rather than weeks. So you want to get the records from the table > weeks. But that table does not have a column week_id, just id and no > idea what you mean by "from the 1(47,48)"Ah, I think I understand. You have a project_id in params[:id] and you want to find the bookings and hence the weeks for that project id? Why don''t you just get the project for the id @project = Project.find params[:id] then the bookings, if you actually need the bookings @bookings = @project.bookings and/or the weeks by @weeks = @project.weeks Colin> > Colin > >> >> But how to I ask that? >> >> >> Am Dienstag, 13. November 2012 14:44:09 UTC+1 schrieb Colin Law: >>> >>> On 13 November 2012 13:34, Werner <webagent...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> > 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 >>> >>> Can you explain again what you want to achieve, I do not understand. >>> >>> Colin >>> >>> > >>> > 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 rubyonra...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> > To unsubscribe from this group, send email to >>> > rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> > 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. >>> > >>> >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.