scinote-web/app/models/asset_text_datum.rb

19 lines
506 B
Ruby
Raw Normal View History

2017-06-23 21:19:08 +08:00
class AssetTextDatum < ApplicationRecord
2016-02-12 23:52:43 +08:00
include SearchableModel
validates :data, presence: true
validates :asset, presence: true, uniqueness: true
2017-06-28 21:21:32 +08:00
belongs_to :asset, inverse_of: :asset_text_datum, optional: true
2016-02-12 23:52:43 +08:00
after_save :update_ts_index
def update_ts_index
2017-07-04 21:00:14 +08:00
if saved_change_to_data?
2016-02-12 23:52:43 +08:00
sql = "UPDATE asset_text_data " +
"SET data_vector = to_tsvector(data) " +
"WHERE id = " + Integer(id).to_s
AssetTextDatum.connection.execute(sql)
end
end
end