From c1cbfddf4ba3a8c916fd69aa90774aa451ca2385 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 13 Sep 2013 15:02:31 +0800 Subject: [PATCH] Fix for user and role relationship (from role and sub-role side) --- lib/tasks/migrate.rake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index 61f3e2f3..7cd8ddaa 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -328,6 +328,26 @@ namespace :migrate do end end end + Role.all.each do |role| + role.user_ids.uniq! + role.save + role.users.each do |user| + unless user.role_ids.include?(role.id) + user.role_ids << role.id + user.save + end + end + end + SubRole.all.each do |sub_role| + sub_role.user_ids.uniq! + sub_role.save + sub_role.users.each do |user| + unless user.sub_role_ids.include?(sub_role.id) + user.sub_role_ids << sub_role.id + user.save + end + end + end end end