diff --git a/app/models/statistic_profile_training.rb b/app/models/statistic_profile_training.rb new file mode 100644 index 000000000..167c42cc7 --- /dev/null +++ b/app/models/statistic_profile_training.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# Stores trainings validated per user (non validated trainings are only recorded in reservations) +class StatisticProfileTraining < ActiveRecord::Base + include NotifyWith::NotificationAttachedObject + + belongs_to :statistic_profile + belongs_to :training + + after_commit :notify_user_training_valid, on: :create + + private + + def notify_user_training_valid + NotificationCenter.call type: 'notify_user_training_valid', + receiver: statistic_profile.user, + attached_object: self + end +end diff --git a/db/migrate/20190605141322_create_statistic_profile_trainings.rb b/db/migrate/20190605141322_create_statistic_profile_trainings.rb new file mode 100644 index 000000000..f6db78b50 --- /dev/null +++ b/db/migrate/20190605141322_create_statistic_profile_trainings.rb @@ -0,0 +1,10 @@ +class CreateStatisticProfileTrainings < ActiveRecord::Migration + def change + create_table :statistic_profile_trainings do |t| + t.belongs_to :statistic_profile, index: true, foreign_key: true + t.belongs_to :training, index: true, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/test/fixtures/statistic_profile_trainings.yml b/test/fixtures/statistic_profile_trainings.yml new file mode 100644 index 000000000..615ea1d02 --- /dev/null +++ b/test/fixtures/statistic_profile_trainings.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + statistic_profile_id: + training_id: + +two: + statistic_profile_id: + training_id: