We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Goal:
How to do:
To get customers which have same email Customer.select('email, count(email)').group('email').having('count(email) > 1')
Customer.select('email, count(email)').group('email').having('count(email) > 1')
Count fields is not null on customer
def count_present_attributes(customer) count = 0 customer.attributes.keys.each do |k| count += 1 if customer.send(k).present? end count end
Destroy duplicate customers
def delete_duplicate_customer Customer.select('email, count(email)').group('email').having('count(email) > 1').each do |customer| customers_with_dup = Customer.where(email: customer.email) customer_to_keep = customers_with_dup.max_by{|cust| count_present_attributes(cust)} customers_to_delete = customers_with_dup.reject{|item| item === customer_to_keep} customers_to_delete.each(&:destroy!) end end
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Goal:
How to do:
To get customers which have same email
Customer.select('email, count(email)').group('email').having('count(email) > 1')
Count fields is not null on customer
Destroy duplicate customers
The text was updated successfully, but these errors were encountered: