diff --git a/app/models/new_plan.rb b/app/models/new_plan.rb index 70b8ca2..1dac7cd 100644 --- a/app/models/new_plan.rb +++ b/app/models/new_plan.rb @@ -1,4 +1,5 @@ class NewPlan < ActiveRecord::Base - has_one :template + belongs_to :template has_many :roles + has_many :users, through: :roles end diff --git a/app/models/user.rb b/app/models/user.rb index c0595e9..9ec7a70 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,6 +11,8 @@ has_many :answers has_many :project_groups, :dependent => :destroy has_many :user_role_types, through: :user_org_roles + has_many :roles + has_many :new_plans, through: :roles belongs_to :language belongs_to :organisation @@ -35,7 +37,7 @@ end end - has_and_belongs_to_many :roles, :join_table => :users_roles + has_and_belongs_to_many :perms, :join_table => :users_perms has_many :plan_sections diff --git a/db/migrate/20161122152339_new_plan_template_structure.rb b/db/migrate/20161122152339_new_plan_template_structure.rb index cfc942e..661ac12 100644 --- a/db/migrate/20161122152339_new_plan_template_structure.rb +++ b/db/migrate/20161122152339_new_plan_template_structure.rb @@ -182,10 +182,11 @@ unless temp_match # no matches found, init template & phase & sections & questions & themes & options puts "creating new template for #{dmptemplate.title}" unless project.organisation.present? puts "creating new template for #{dmptemplate.title} customised by #{project.organisation.name}" unless project.organisation.nil? - modifiable = project.organisation.nil? + modifiable = project.organisation.nil? || project.organisation_id == dmptemplate.organisation_id template = initTemplate(dmptemplate, modifiable, project.organisation_id) # needs to select next version of temp based on old_temp_id # some differences between a customised and un-customised template # customised templates need a different organisation_id + template.organisation_id = project.organisation_id unless project.organisation_id.nil? # updated to not overwrite with nil # customised templates follow different version rules template.save! # since template was not a match, need to gen/copy all data below the template level @@ -255,7 +256,7 @@ end end end - + # indexes on join tables at the end change_table :new_answers_question_options do |t| t.index [:new_answer_id, :question_option_id], name: 'answer_question_option_index' @@ -435,4 +436,4 @@ role.user_id = project_group.user_id role.new_plan_id = new_plan.id return role -end \ No newline at end of file +end