Sha256: e495c0a0c4a1cf2ccebb5ef03c5b45d23c4c41069cd54a3e5ec5b2391a9c78ef

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 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]
        foreign_key_name = @options[:foreign_key_name]
        if foreign_key_name == "dn"
          old_value = dn_values_to_string_values(old_value)
        end
        new_value = old_value + @owner[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]
          foreign_key_name = @options[:foreign_key_name]
          if foreign_key_name == "dn"
            old_value = dn_values_to_string_values(old_value)
          end
          new_value = old_value - @owner[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
        values = @owner[@options[:foreign_key_name], true].compact
        return [] if values.empty?

        key = @options[:many]
        components = values.collect do |value|
          [key, value]
        end
        options = find_options(:filter => [:or, *components])
        foreign_class.find(:all, options)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activeldap-1.0.2 lib/active_ldap/association/belongs_to_many.rb
activeldap-1.0.9 lib/active_ldap/association/belongs_to_many.rb
activeldap-1.0.1 lib/active_ldap/association/belongs_to_many.rb