5
5

More than 5 years have passed since last update.

hair_triggerはもはや死んだプロジェクトで、モダンな環境では使えない。

Last updated at Posted at 2014-04-23

HairTrigger

Activerecordに経由でトリガーを付与するgemっぽい。

感想

もはや死んだプロジェクトで、モダンな環境では使えない。
普通にmigrationファイルにトリガー書いた方がよさげ

execute <<-SQL
        CREATE TRIGGER my_trigger ...
    SQL

蛇足:リドミの和訳

Compatibility

  • Ruby 1.8.7+
  • Rails 2.3+
  • Postgres 8.0+
  • MySQL 5.0.10+
  • SQLite 3.3.8+

古そう。心配。

インストール

Gemfileに gem 'hairtrigger'

使い方

Models

models でトリガーを定義、rake taskでmigrationを作成する。

class AccountUser < ActiveRecord::Base
  trigger.after(:insert) do
    "UPDATE accounts SET user_count = user_count + 1 WHERE id = NEW.account_id;"
  end
end

と記述したあと、

rake db:generate_trigger_migration

とやると下記のような命令がDBMSに対して実行されるらしい。

CREATE TRIGGER account_users_after_insert_row_tr AFTER INSERT ON account_users
FOR EACH ROW
BEGIN
    UPDATE accounts SET user_count = user_count + 1 WHERE id = NEW.account_id;
END
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5