Would merge work? Something like (off the top of my head): Shift.includes(:schedules).merge(Schedule.occuring_on(Date.today))
where .occuring_on is def self.occuring_on(day) where(:occurs_on => day) end -Corey On Thu, Oct 4, 2012 at 3:44 PM, r1git <erwan.ha...@gmail.com> wrote: > Does anybody know how to fix this issue: > https://github.com/rails/rails/issues/4677 ? > > It seems so basic and yet there is no clean solution like conditional eager > loading, something like: > > Shift.includes(:schedules).where(:schedules => { :occurs_on => Date.today }) > > Or another solution would be threw a join request like: > > SELECT shifts.*,schedules.* from shifts LEFT JOIN schedules ON > (schedules.shift_id = shifts.id AND schedules.occurs_on = Date.today); > > But using this in a Shift.joins("LEFT JOIN schedules ON (schedules.shift_id > = shifts.id AND schedules.occurs_on = ?", Date.today) fails to return a > properly filled Shift arrays. And any access to the Shift.schedules launch a > new SQL request forgeting the occurs_on constraint... > > Thanks for any help > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/tlvdnKOgj-cJ. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.