diff --git a/app/models/impediment.rb b/app/models/impediment.rb index 7badaca2ba..d8d5e92bca 100644 --- a/app/models/impediment.rb +++ b/app/models/impediment.rb @@ -35,7 +35,7 @@ class Impediment < Task end def blocks_ids - @blocks_ids_list ||= relations_from.select{ |rel| rel.relation_type == IssueRelation::TYPE_BLOCKS }.collect(&:work_package_to_id) + @blocks_ids_list ||= relations_from.select{ |rel| rel.relation_type == Relation::TYPE_BLOCKS }.collect(&:to_id) end private @@ -47,15 +47,15 @@ class Impediment < Task end def remove_from_blocks_list - self.relations_from.delete(self.relations_from.select{|rel| rel.relation_type == IssueRelation::TYPE_BLOCKS && !blocks_ids.include?(rel.work_package_to_id) }) + self.relations_from.delete(self.relations_from.select{|rel| rel.relation_type == Relation::TYPE_BLOCKS && !blocks_ids.include?(rel.to_id) }) end def add_to_blocks_list - currently_blocking = relations_from.select{|rel| rel.relation_type == IssueRelation::TYPE_BLOCKS}.collect(&:work_package_to_id) + currently_blocking = relations_from.select{|rel| rel.relation_type == Relation::TYPE_BLOCKS}.collect(&:to_id) (self.blocks_ids - currently_blocking).each{ |id| - rel = IssueRelation.new(:relation_type => IssueRelation::TYPE_BLOCKS, :work_package_from => self) - rel.work_package_to_id = id #attr_protected + rel = Relation.new(:relation_type => Relation::TYPE_BLOCKS, :from => self) + rel.to_id = id #attr_protected self.relations_from << rel } end diff --git a/lib/open_project/backlogs/hooks.rb b/lib/open_project/backlogs/hooks.rb index 912630ec84..44a2c5752a 100644 --- a/lib/open_project/backlogs/hooks.rb +++ b/lib/open_project/backlogs/hooks.rb @@ -154,11 +154,11 @@ module OpenProject::Backlogs::Hooks if work_package.is_story? if params[:link_to_original] - rel = IssueRelation.new + rel = Relation.new - rel.work_package_from_id = Integer(params[:link_to_original]) - rel.work_package_to_id = work_package.id - rel.relation_type = IssueRelation::TYPE_RELATES + rel.from_id = Integer(params[:link_to_original]) + rel.to_id = work_package.id + rel.relation_type = Relation::TYPE_RELATES rel.save end diff --git a/lib/open_project/backlogs/patches/query_patch.rb b/lib/open_project/backlogs/patches/query_patch.rb index 2fd5c0ea57..e47a9db60b 100644 --- a/lib/open_project/backlogs/patches/query_patch.rb +++ b/lib/open_project/backlogs/patches/query_patch.rb @@ -57,11 +57,11 @@ module OpenProject::Backlogs::Patches::QueryPatch sql << "(#{db_table}.type_id = #{Task.type} AND NOT #{db_table}.parent_id IS NULL)" when "impediment" sql << "(#{db_table}.id IN ( - select work_package_from_id + select from_id FROM issue_relations ir JOIN work_packages blocked ON - blocked.id = ir.issue_to_id + blocked.id = ir.to_id AND blocked.type_id IN (#{all_types}) WHERE ir.relation_type = 'blocks' ) AND #{db_table}.parent_id IS NULL)" diff --git a/spec/models/impediment_spec.rb b/spec/models/impediment_spec.rb index d4060e0491..875e04c258 100644 --- a/spec/models/impediment_spec.rb +++ b/spec/models/impediment_spec.rb @@ -80,7 +80,7 @@ describe Impediment do shared_examples_for "impediment creation with 1 blocking relationship" do it_should_behave_like "impediment creation" it { @impediment.should have(1).relations_from } - it { @impediment.relations_from[0].issue_to.should eql feature } + it { @impediment.relations_from[0].to.should eql feature } it { @impediment.relations_from[0].relation_type.should eql Relation::TYPE_BLOCKS } end @@ -186,7 +186,7 @@ describe Impediment do it_should_behave_like "impediment update" it { @impediment.should have(1).relations_from } it { @impediment.relations_from[0].should_not be_new_record } - it { @impediment.relations_from[0].issue_to.should eql @story } + it { @impediment.relations_from[0].to.should eql @story } it { @impediment.relations_from[0].relation_type.should eql Relation::TYPE_BLOCKS } end @@ -194,7 +194,7 @@ describe Impediment do it_should_behave_like "impediment update" it { @impediment.should have(1).relations_from } it { @impediment.relations_from[0].should_not be_changed } - it { @impediment.relations_from[0].issue_to.should eql feature } + it { @impediment.relations_from[0].to.should eql feature } it { @impediment.relations_from[0].relation_type.should eql Relation::TYPE_BLOCKS } end