I need to decrease the counter of active users in a group, actually is increasing correctly when a new user pass from inactive to active in the group. But when change from active to inactive and then to active again the counter of active users is one more.
So what I need is to decrease the counter when passing from active to inactive.
Until now I tried to use the delta_magnitude
param to make it decrease but didn't work.
class GroupUser < ApplicationRecord
attr_accessor :send_challenge
belongs_to :group
belongs_to :user
counter_culture :group, column_name: proc { |model| model.active? ? 'users_count' : nil },
column_names: {
['group_users.active = ?', true] => 'users_count'
}
As you can see I use the dynamic-column-names
class GroupUser < ApplicationRecord
attr_accessor :send_challenge
belongs_to :group
belongs_to :user
counter_culture :group, column_name: proc { |model| model.active? ? 'users_count' : nil },
column_names: {
['group_users.active = ?', true] => 'users_count'
},
delta_magnitude: 1
Here I add the delta-magnitude trying to make it decrease but didn't work.
I there a way to express a condition to make it decrease?
At the end I just decrease it manually in the same query that change from active to inactive. If someone knows the correct answer it will be useful next time.