lib/mongoid_nested_set/validation.rb
def no_duplicates_for_fields?
      roots.group_by{|record| scope_field_names.collect{|field| record.send(field.to_sym)}}.all? do |scope, grouped_roots|
        [left_field_name, right_field_name].all? do |field|
          grouped_roots.first.nested_set_scope.only(field).group_by {|doc| doc.send(field)}.all? {|k, v| v.size == 1}
        end
      end
    end
def no_duplicates_for_fields?
      roots.group_by{|record| scope_field_names.collect{|field| record.send(field.to_sym)}}.all? do |scope, grouped_roots|
        [left_field_name, right_field_name].all? do |field|
          grouped_roots.first.nested_set_scope.only(field).group_by {|doc| doc.send(field)}.all? {|k, v| v.size == 1}
        end
      end
    end
def no_duplicates_for_fields? roots . group_by { | record | scope_field_names . collect { | field | record . send ( field . to_sym ) } } . all? do | scope , grouped_roots | [ left_field_name , right_field_name ] . all? do | field | grouped_roots . first . nested_set_scope . only ( field ) . group_by { | doc | doc . send ( field ) } . all? { | k , v | v . size == 1 } end end end
Warning: Very expensive!  Do not use unless you know what you are doing.
Warning : Very expensive! Do not use unless you know what you are doing .