Add association between repository rows & my modules

This commit is contained in:
Luka Murn 2017-05-30 15:09:39 +02:00
parent ef1ecdd7c7
commit bb20d2661f
2 changed files with 24 additions and 0 deletions

View file

@ -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

View file

@ -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