Skip to content

Instantly share code, notes, and snippets.

@chrisyour
Created April 8, 2011 16:59
Show Gist options
  • Save chrisyour/910275 to your computer and use it in GitHub Desktop.
Save chrisyour/910275 to your computer and use it in GitHub Desktop.
Change to ActiveRecord's associations.rb (around line 1500)
if reflection.options[:conditions]
reflection_table = (reflection.options[:class_name] || reflection.options[:source] || reflection.name).gsub('::', '_').tableize
if reflection.options[:conditions].to_s.include?("#{reflection_table}")
send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").joins(reflection.options[:source]).where(reflection.options[:conditions]).map! { |r| r.send(primary_key) }
else
send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").where(reflection.options[:conditions]).map! { |r| r.send(primary_key) }
end
else
send(through.name).select("DISTINCT #{through.quoted_table_name}.#{primary_key}").map! { |r| r.send(primary_key) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment