From afd8e7e3805214685004da6a7b169ce8569139ba Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 5 Dec 2012 13:49:53 +0800 Subject: [PATCH] when delete co-author relation, the co-author will be reset nil --- app/controllers/desktop/co_author_relations_controller.rb | 1 + app/helpers/desktop/co_author_relations_helper.rb | 6 ++++++ db/seeds.rb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/desktop/co_author_relations_controller.rb b/app/controllers/desktop/co_author_relations_controller.rb index f35391dd..edeeacb8 100644 --- a/app/controllers/desktop/co_author_relations_controller.rb +++ b/app/controllers/desktop/co_author_relations_controller.rb @@ -27,6 +27,7 @@ class Desktop::CoAuthorRelationsController < ApplicationController def destroy @co_author_relation = CoAuthorRelation.find(params[:id]) @co_author_relation.destroy + #reset_co_author_relation @co_author_relation render :json => {success: true, msg: "deleted successfully!"} end diff --git a/app/helpers/desktop/co_author_relations_helper.rb b/app/helpers/desktop/co_author_relations_helper.rb index fa03bbae..7de13211 100644 --- a/app/helpers/desktop/co_author_relations_helper.rb +++ b/app/helpers/desktop/co_author_relations_helper.rb @@ -1,2 +1,8 @@ module Desktop::CoAuthorRelationsHelper + def reset_co_author_relation relation + co_author = CoAuthor.where(co_author_relations_id: relation) + co_author.map do |c| + co_author.update_attributes(co_author_relations_id: nil) + end + end end diff --git a/db/seeds.rb b/db/seeds.rb index 9c90554c..c9dd1c3d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -33,7 +33,7 @@ FactoryGirl.define do { zh_tw: "#{name_tw[n]}", en: "#{name_en[n]}" } end - f.sequence(:type) do |n| "#{type[n%5]}" end + f.sequence(:co_author_relations_id) do |n| "#{CoAuthorRelation.all[n%type.size].id}" end f.sequence(:email) do |n| "#{email[n]}" end f.name_id BSON::ObjectId('4f45f3b9e9d02c5db9000067') #user_id, this is Chris' account end