Top Menu

Jump to content
Home
    Modules
      • Projects
      • Activity
      • Work packages
      • Gantt charts
      • Calendars
      • Team planners
      • Boards
      • News
    • Getting started
    • Introduction video
      Welcome to OpenProject Community
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • Upgrade to Enterprise edition
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Enterprise support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Forgot your password?

      or sign in with your existing account

      Google

Side Menu

  • Overview
  • Activity
    Activity
  • Roadmap
  • Work packages
    Work packages
  • Gantt charts
    Gantt charts
  • Calendars
    Calendars
  • Team planners
    Team planners
  • Boards
    Boards
  • News
  • Forums

Content

Development
  1. OpenProject
  2. Forums
  3. Development
  4. How to implement associations between plugin tables and existing OpenProject tables?

How to implement associations between plugin tables and existing OpenProject tables?

Added by Vĩnh Khang Lê over 6 years ago

I'm developing a Service Pack plugin allowing user to track units from purchased service pack when user log time for tasks. My issues is the new tables must relate to the existing OpenProject tables. In this case, we have to implement two "has-many through" associations, which are between ServicePacks and Projects, and between ServicePack and Enumerations,  that requires modifying the OpenProject code. Is there any way to implement these associations from the plugin without modifying the existing OP core?


Replies (3)

RE: How to implement associations between plugin tables and existing OpenProject tables? - Added by Oliver Günther over 6 years ago

Hi,

with our Rails plugins hooks, you can patch the OpenProject core by simply extending modules within a plugin due to Ruby's metaprogramming.

See the following easy example: The Documents plugin patches the Project class  with the following code:

module OpenProject::Documents::Patches
  module ProjectPatch
    def self.included(base)
      base.class_eval do

        has_many :documents, dependent: :destroy
      end
    end
  end
end

Project.send(:include, OpenProject::Documents::Patches::ProjectPatch)

Source: https://github.com/opf/openproject/blob/dev/modules/documents/lib/open_project/documents/patches/project_patch.rb

This patch is registered at the engine of the plugin here: https://github.com/opf/openproject/blob/dev/modules/documents/lib/open_project/documents/engine.rb#L65

Best,

Oliver

RE: How to implement associations between plugin tables and existing OpenProject tables? - Added by Vĩnh Khang Lê over 6 years ago

thank you, I have successfully implement the associations following your guide. However, i'm having a new problem. I want use Action Mailer to send email to user if the Service Pack has expired. I have generate the ServicePackMailer following rails guide but I can not preview the ServicePackMailer when I start the OP. It said the mailer not found. The same after I try re-bundle install. Do I have to register something in the engine file like the last problem?

RE: How to implement associations between plugin tables and existing OpenProject tables? - Added by Charlie Kearns over 1 year ago

This patch is registered at the engine of the plugin here: https://github.com/opf/openproject/blob/dev/modules/documents/lib/open_project/documents/engine.rb#L65 uno online

This is what I am looking for, Thanks for sharing it.

  • (1 - 3/3)
Loading...