On 13 Jul 2011, at 20:23, Vijay Dev <vijaydev....@gmail.com> wrote:
> Given a school model and a student model with the school having a has_many
> relation to student:
>
> has_many :students, :conditions => proc { "year_id=#{send(:active_year_id)}"
> }
>
> where active_year_id is a method defined in the school model, I'm
> encountering an error that "active_year_id is undefined" when calling:
>
> School.where(:active => true).includes(:students)
>
> The condition works fine when I do, say, School.where(:id => 10).students.
>
> Only when I try to use includes do I get that error. Is that the right
> behavior. If not, what am I doing wrong and how do I fix ?
Interpolated conditions on associations have never worked with includes, since
the point would be to load all students in one go which you can't do in general
if each one has different conditions.
For join based includes I believe this is flat out impossible. For the other
form you might be able to crowbar it in, but it feels very tricky
Fred
>
> Using Rails 3.0.9, REE 1.8.7.
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/9rsY1unEtsEJ.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
--
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+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.