mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 18:21:04 +08:00
19 lines
452 B
Ruby
19 lines
452 B
Ruby
|
class AssetTextDatum < ActiveRecord::Base
|
||
|
include SearchableModel
|
||
|
|
||
|
validates :data, presence: true
|
||
|
validates :asset, presence: true, uniqueness: true
|
||
|
belongs_to :asset
|
||
|
|
||
|
after_save :update_ts_index
|
||
|
|
||
|
def update_ts_index
|
||
|
if data_changed?
|
||
|
sql = "UPDATE asset_text_data " +
|
||
|
"SET data_vector = to_tsvector(data) " +
|
||
|
"WHERE id = " + Integer(id).to_s
|
||
|
AssetTextDatum.connection.execute(sql)
|
||
|
end
|
||
|
end
|
||
|
end
|