lib/groupify/adapter/mongoid.rb in groupify-0.4.2 vs lib/groupify/adapter/mongoid.rb in groupify-0.5.0
- old
+ new
@@ -50,21 +50,23 @@
included do
@default_member_class = nil
@member_klasses ||= Set.new
end
-
+
def members
self.class.default_member_class.any_in(:group_ids => [self.id])
end
def member_classes
self.class.member_classes
end
- def add(member)
- member.groups << self
+ def add(*members)
+ members.flatten.each do |member|
+ member.groups << self
+ end
end
# Merge a source group into this group.
def merge!(source)
self.class.merge!(source, self)
@@ -108,12 +110,13 @@
raise ArgumentError.new("#{source_group.class} has members that cannot belong to #{destination_group.class}")
end
end
source_group.member_classes.each do |klass|
- klass.any_in(:group_ids => [source_group.id]).update(:$set => {:"group_ids.$" => destination_group.id})
+ klass.any_in(:group_ids => [source_group.id]).update_all(:$set => {:"group_ids.$" => destination_group.id})
end
- source_group.destroy
+
+ source_group.delete
end
protected
def register(member_klass)
\ No newline at end of file