From bb20d2661f3f0ec90bb2060874ddf1b57d27f319 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 30 May 2017 15:09:39 +0200 Subject: [PATCH] Add association between repository rows & my modules --- app/models/repository_row_my_module.rb | 12 ++++++++++++ .../20170530150200_add_repository_row_my_modules.rb | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 app/models/repository_row_my_module.rb create mode 100644 db/migrate/20170530150200_add_repository_row_my_modules.rb diff --git a/app/models/repository_row_my_module.rb b/app/models/repository_row_my_module.rb new file mode 100644 index 000000000..f945739bd --- /dev/null +++ b/app/models/repository_row_my_module.rb @@ -0,0 +1,12 @@ +class RepositoryRowMyModule < ActiveRecord::Base + validates :repository_row, :my_module, presence: true + + # One row can only be assigned once to a specific module + validates_uniqueness_of :repository_row_id, :scope => :my_module_id + + belongs_to :assigned_by, foreign_key: 'assigned_by_id', class_name: 'User' + belongs_to :repository_row, + inverse_of: :repository_row_my_modules + belongs_to :my_module, + inverse_of: :repository_row_my_modules +end diff --git a/db/migrate/20170530150200_add_repository_row_my_modules.rb b/db/migrate/20170530150200_add_repository_row_my_modules.rb new file mode 100644 index 000000000..65f9940c3 --- /dev/null +++ b/db/migrate/20170530150200_add_repository_row_my_modules.rb @@ -0,0 +1,12 @@ +class AddRepositoryRowMyModules < ActiveRecord::Migration + def change + create_table :repository_row_my_modules do |t| + t.belongs_to :repository_row, index: true + t.belongs_to :my_module, index: true + t.integer :assigned_by_id, null: false + t.timestamps null: true + end + + add_foreign_key :repository_row_my_modules, :users, column: :assigned_by_id + end +end