Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Consistent crc/class attributes.

  • Loading branch information...
commit 01c72a0996c5fa14fe444f82669c64aa29470aec 1 parent 3f13fee
@pat pat authored
Showing with 21 additions and 4 deletions.
  1. +21 −4 lib/thinking_sphinx/source/sql.rb
View
25 lib/thinking_sphinx/source/sql.rb
@@ -121,7 +121,7 @@ def crc_column
return @model.to_crc32.to_s if types.empty?
adapter.case(adapter.convert_nulls(
- adapter.quote_with_table(@model.inheritance_column)),
+ adapter.quote_with_table(@model.inheritance_column), @model.name),
types, @model.to_crc32)
else
@model.to_crc32.to_s
@@ -129,16 +129,26 @@ def crc_column
end
def internal_class_column
+ quoted_name = "'#{@model.name}'"
+
if @model.table_exists? &&
@model.column_names.include?(@model.inheritance_column)
- adapter.quote_with_table(@model.inheritance_column)
+
+ types = types_to_hash
+ return quoted_name if types.empty?
+
+ adapter.case(adapter.convert_nulls(
+ adapter.quote_with_table(@model.inheritance_column), @model.name),
+ types, quoted_name)
else
- "'#{@model.name}'"
+ quoted_name
end
end
def type_values
- @model.sphinx_types.presence or @model.connection.select_values <<-SQL
+ return @model.sphinx_types unless @model.sphinx_types.nil?
+
+ @model.connection.select_values <<-SQL
SELECT DISTINCT #{@model.inheritance_column}
FROM #{@model.table_name}
SQL
@@ -150,6 +160,13 @@ def types_to_crcs
hash
}
end
+
+ def types_to_hash
+ type_values.compact.inject({}) { |hash, type|
+ hash[type] = "'#{type}'"
+ hash
+ }
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.