# Provide more details when performing a bulk add to group

**URL:** <https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665>\
**Category:** Feature\
**Tags:** groups\
**Created:** [4월 9, 2017, 3:37오전 UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665 "2017-04-09T03:37:56Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [4월 26, 2017, 5:19오후 UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/7 "2017-04-26T17:19:44Z")

</div>

You could probably do it with one query if you did something like this (off the top of my head, untested):

```ruby
found_users = User.where("username_lower in (:users) OR email IN (:users)", users: users).pluck(:id, :username_lower, :email)

# convert to hash to make searching faster
found_emails = {}
found_usernames = {}

found_users.each do |fu| 
  found_emails[fu[1]] = fu[0]
  found_usernames[fu[2]] = fu[0]
end

not_found = users.reject? {|u| found_emails[u] || found_usernames[u]}

```

Then `not_found` would include all the users inputted that weren’t returned by the SQL query.

---

_[View the full topic](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665)._
