conditions+=" AND #{association_class.send(:type_condition).to_sql}"ifassociation_class.finder_needs_type_condition?
# Add custom conditions
conditions+=" AND (#{interpolate_sql(association_class.send(:sanitize_sql,reflection.options[:conditions]))})"ifreflection.options[:conditions]
ifreflection.macro==:belongs_to
ifreflection.options[:polymorphic]
conditions+=" AND #{local_table_alias}.#{reflection.options[:foreign_type]} = #{reflection.active_record.quote_value(association_class.base_class.name.to_s)}"
conditions+=" AND #{remote_table_alias}.#{reflection.options[:as]}_type = #{reflection.active_record.quote_value(reflection.active_record.base_class.name.to_s)}"