Sha256: 56acf11715462314ff164605a1f7c7a0f23c0d83a367bdccdc158bec0c3672c8

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

require 'active_ldap/association/collection'

module ActiveLdap
  module Association
    class BelongsToMany < Collection
      private
      def insert_entry(entry)
        old_value = entry[@options[:many], true]
        new_value = old_value + @owner[@options[:foreign_key_name], true]
        new_value = new_value.uniq.sort
        if old_value != new_value
          entry[@options[:many]] = new_value
          entry.save
        end
      end

      def delete_entries(entries)
        entries.each do |entry|
          old_value = entry[@options[:many], true]
          new_value = old_value - @owner[@options[:foreign_key_name], true]
          new_value = new_value.uniq.sort
          if old_value != new_value
            entry[@options[:many]] = new_value
            entry.save
          end
        end
      end

      def find_target
        key = @options[:many]
        filter = @owner[@options[:foreign_key_name], true].reject do |value|
          value.nil?
        end.collect do |value|
          "(#{key}=#{value})"
        end.join
        foreign_class.find(:all, :filter => "(|#{filter})")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-activeldap-0.8.0 lib/active_ldap/association/belongs_to_many.rb
ruby-activeldap-0.8.1 lib/active_ldap/association/belongs_to_many.rb