Simplify setting tsvector values

We make the code easier to read and at the same time we remove a SQL
injection false positive regarding the use of `WHERE id = #{id}`.

We still get a warning about SQL injection regarding the `tsv =` part.
It's a false positive, since the value of that parameter does not
depend on user input.
This commit is contained in:
Javi Martín
2019-11-10 20:36:22 +01:00
parent d746401862
commit 55d339572c

View File

@@ -6,8 +6,7 @@ module SearchCache
end
def calculate_tsvector
ActiveRecord::Base.connection.execute("
UPDATE #{self.class.table_name} SET tsv = (#{searchable_values_sql}) WHERE id = #{id}")
self.class.where(id: id).update_all("tsv = (#{searchable_values_sql})")
end
private