File: has_many.rb

package info (click to toggle)
ruby-activeldap 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,588 kB
  • sloc: ruby: 18,143; sh: 12; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 804 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'active_ldap/association/collection'
require 'active_ldap/association/has_many_utils'

module ActiveLdap
  module Association
    class HasMany < Collection
      include HasManyUtils

      private
      def insert_entry(entry)
        entry[foreign_key] = @owner[primary_key]
        entry.save
      end

      def find_target
        collect_targets(primary_key)
      end

      def delete_entries(entries)
        _foreign_key = foreign_key
        components = @owner[primary_key, true].reject do |value|
          value.nil?
        end
        filter = [:and,
                  [:and, {_foreign_key => components}],
                  [:or, {foreign_class.dn_attribute => entries.collect(&:id)}]]
        foreign_class.update_all({_foreign_key => []}, filter)
      end
    end
  end
end