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