Plugin Development and Models
I'm writing a Todos plugin, and I'm wondering how I can "modify" the Project model without actually modifying it in the application.
I want to inject a has_many into the Project model, and I'm unsure how to accomplish this.
Does anyone have any comments or ideas? I'd be happy to put some information about this in the wiki when I'm done working out all the details. Is this even possible?
RE: Plugin Development and Models - Added by Eric Davis almost 10 years ago
This should work for you:
# init.rb # ... normal plugin init stuff ... module ProjectPatch def self.included(base) # Same as typing in the class base.class_eval do unloadable # Send unloadable so it will not be unloaded in development has_many :todos end end end Project.send(:include, ProjectPatch)
You can also extend a core Model with additional behaviors. For an example, check out
issue_patch.rb in my Budget plugin (https://projects.littlestreamsoftware.com/repositories/entry/redmine-budget/lib/issue_patch.rb)