On Wednesday, January 13, 2016 at 12:13:36 PM UTC-5, Jim wrote: > > > If you want to load matching As without instantiating the Cs, you could do > something like: > > A.where(id: C.where(code: params[:codes]).pluck(:a_id)) > > If you are going to instantiate all As and Cs found anyway, you could just > use eager loading: > > found_c = C.where(code: params[:codes]).includes(:a) > found_a = found_c.collect(&:a).uniq >
I missed the requirement that each A found should contain *all* desired C records. These queries will find As with *any* of the C records found. Jim Crate -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e78790a2-a404-4a10-8f67-6579533d35a7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.