# File lib/thinking_sphinx/active_record/filtered_reflection.rb, line 9 def initialize(reflection, class_name) @reflection, @class_name = reflection, class_name @options = reflection.options.clone end
# File lib/thinking_sphinx/active_record/filtered_reflection.rb, line 14 def options @options.delete :polymorphic @options[:class_name] = class_name @options[:foreign_key] ||= "#{reflection.name}_id" @options[:foreign_type] = reflection.foreign_type return @options if reflection.respond_to?(:scope) case @options[:conditions] when nil @options[:conditions] = condition when Array @options[:conditions] << condition when Hash @options[:conditions].merge!(reflection.foreign_type => @options[:class_name]) else @options[:conditions] << " AND #{condition}" end @options end
# File lib/thinking_sphinx/active_record/filtered_reflection.rb, line 36 def scope lambda { |association| reflection = association.reflection where( association.parent.aliased_table_name.to_sym => {reflection.foreign_type => reflection.class_name} ) } end
# File lib/thinking_sphinx/active_record/filtered_reflection.rb, line 48 def condition "::ts_join_alias::.#{quoted_foreign_type} = '#{class_name}'" end
# File lib/thinking_sphinx/active_record/filtered_reflection.rb, line 52 def quoted_foreign_type active_record.connection.quote_column_name foreign_type end