module Backend
  module Groups
    extend self
    def create(groupname:, usernames:)
      group = Group.new
      group.groupname = groupname
      group.users << User.where(username: usernames)
      group.save!
      group
    end
  end
end

module Backend
  module Groups
    extend self
    def create(groupname:, usernames:)
      group = Group.new
      group.groupname = groupname
      group.users << usernames.map{ |username| User.where(username: username).first }
      group.save!
      group
    end
  end
end

--- 
+++ 
@@ -4,7 +4,7 @@
     def create(groupname:, usernames:)
       group = Group.new
       group.groupname = groupname
-      group.users << usernames.map{ |username| User.where(username: username).first }
+      group.users << User.where(username: usernames)
       group.save!
       group
     end
Use sql rather than ruby loop
