-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix multiple financial officer issue
- Loading branch information
1 parent
8b836d2
commit a3b99eb
Showing
10 changed files
with
125 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
db/migrate/20220520160742_remove_financial_officers_if_more_then_one.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class RemoveFinancialOfficersIfMoreThenOne < ActiveRecord::Migration[6.0] | ||
def up | ||
groups_with_fo_count = Group.joins(memberships: :posts) | ||
.where('posts.post_type_id': PostType::FINANCIAL_OFFICER_POST_ID) | ||
.group('memberships.group_id').count('groups.id') | ||
group_ids_with_more_fo = groups_with_fo_count.select { |k, v| v > 1 }.keys | ||
groups_with_more_fo = Group.where(id: group_ids_with_more_fo) | ||
groups_with_more_fo.each do |group| | ||
fo_posts = Post.where('memberships.group_id': group.id, | ||
post_type_id: PostType::FINANCIAL_OFFICER_POST_ID) | ||
.joins(:membership).order('posts.id': :asc) | ||
fo_posts[0..-2].each { |post| post.destroy! } | ||
end | ||
end | ||
|
||
def down;end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters