0
Following this guide here,我想添加一個觸發器,它更新模型的多個屬性。以下是我現在有:Rails,添加一個觸發器來更新多個列
class AddTriggerToArguments < ActiveRecord::Migration[5.0]
def up
execute %{
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
ON arguments FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(tsv_body, 'pg_catalog.simple', description);
}
end
def down
execute %{DROP TRIGGER tsvectorupdate ON arguments}
end
end
正如你可以在該行
tsvector_update_trigger(tsv_body, 'pg_catalog.simple', description);
看到更新的描述屬性。但是我需要做什麼,以便更新多個屬性?
我的模型標題和描述爲屬性。我想爲觸發器添加標題。我試過這個,但它沒有工作:
def up
execute %{
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
ON arguments FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(tsv_body, 'pg_catalog.simple', description)
tsvector_update_trigger(tsv_body, 'pg_catalog.simple', title);
}
end
但是沒有奏效。誰能幫我?