Skip to content

Commit

Permalink
refs #30: Patch TimeEntry to relate TogglMapping.
Browse files Browse the repository at this point in the history
When a TimeEntry is deleted, related TogglMapping records are also deleted.
  • Loading branch information
jigarius committed Oct 5, 2019
1 parent cac15fb commit f1b6ad9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
{ controller: 't2r', action: 'index' },
caption: 'Toggl'
end

# Patches.
require 'patches/time_entry.rb'
15 changes: 15 additions & 0 deletions lib/patches/time_entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Patch Redmine's TimeEntry model.
#
# When a time entry is deleted, all related Toggl mappings should be deleted.
module Toggl2Redmine
module TimeEntryPatch
def self.included(base)
base.class_eval do
unloadable # To not unload in development?
has_many :toggl_mappings, dependent: :destroy
end
end
end
end

TimeEntry.send(:include, Toggl2Redmine::TimeEntryPatch)

0 comments on commit f1b6ad9

Please sign in to comment.