Changed Unit uniqueness condtions to shortname only
This commit is contained in:
parent
b0a02b7474
commit
b1be5e571a
@ -27,9 +27,10 @@ class UnitsController < ApplicationController
|
||||
end
|
||||
|
||||
def import
|
||||
available = Unit.where(project: @project).pluck(:shortname)
|
||||
defaults = Unit.where(project: nil).pluck(:name, :shortname)
|
||||
missing = defaults - Unit.where(project: @project).pluck(:name, :shortname)
|
||||
@project.units.create(missing.map { |n, s| {name: n, shortname: s} })
|
||||
defaults.delete_if { |n, s| available.include?(s) }
|
||||
@project.units.create(defaults.map { |n, s| {name: n, shortname: s} })
|
||||
|
||||
redirect_to project_units_url(@project)
|
||||
end
|
||||
|
@ -2,5 +2,6 @@ class Unit < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
|
||||
validates :project, associated: true
|
||||
validates :name, :shortname, presence: true, uniqueness: true
|
||||
validates :name, presence: true
|
||||
validates :shortname, presence: true, uniqueness: {scope: :project_id}
|
||||
end
|
||||
|
@ -15,4 +15,4 @@ en:
|
||||
index:
|
||||
heading: 'Units'
|
||||
heading_new_unit: 'New unit'
|
||||
heading_import: 'Import'
|
||||
heading_import: 'Import defaults'
|
||||
|
Reference in New Issue
Block a user