can i add database trigger on plugin?
Added by rangga rahadian over 8 years ago
im new to redmine plugin development, need much help
can i add databse trigger on db migration or on else? as example, when the issue status field on table issue changes, it triggered to change other field values on another table.
if it can, give me litte example how to write trigger on the plugin
thanks, really appreciate for your help
Replies (2)
RE: can i add database trigger on plugin? - Added by Martin Denizet (redmine.org team member) over 8 years ago
Look into the after_save
callback
You have to create a plugin to inject the after_save
behavior.
A very simplistic use case for a model called TargetModel would be (Didn't test, dummy code):
module MyPlugin
module TargetModelPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
after_save :my_custom_callback
end
end
module InstanceMethods
def my_custom_callback
# Insert code to be called after TargetModel is saved (created or updated)
# use 'self' to get the current TargetModel instance
end
end
end
TargetModel.send(:include, MyPlugin::TargetModelPatch)
Cheers,
-Martin