| Class | ActiveLdap::Association::BelongsToMany |
| In: |
lib/active_ldap/association/belongs_to_many.rb
|
| Parent: | Collection |
# File lib/active_ldap/association/belongs_to_many.rb, line 25
25: def delete_entries(entries)
26: _foreign_class = foreign_class
27: entries.each do |entry|
28: entry = _foreign_class.find(entry) unless entry.is_a?(_foreign_class)
29: old_value = entry[@options[:many], true]
30: primary_key_name = @options[:primary_key_name]
31: if primary_key_name == "dn"
32: old_value = dn_values_to_string_values(old_value)
33: end
34: current_value = @owner[primary_key_name, true]
35: current_value = dn_values_to_string_values(current_value)
36: new_value = old_value - current_value
37: new_value = new_value.uniq.sort
38: if old_value != new_value
39: entry[@options[:many]] = new_value
40: entry.save
41: end
42: end
43: end
# File lib/active_ldap/association/belongs_to_many.rb, line 45
45: def find_target
46: values = @owner[@options[:primary_key_name], true].compact
47: return [] if values.empty?
48:
49: key = @options[:many]
50: components = values.collect do |value|
51: [key, value]
52: end
53: options = find_options(:filter => [:or, *components])
54: foreign_class.find(:all, options)
55: end
# File lib/active_ldap/association/belongs_to_many.rb, line 7
7: def insert_entry(entry)
8: _foreign_class = foreign_class
9: entry = _foreign_class.find(entry) unless entry.is_a?(_foreign_class)
10: old_value = entry[@options[:many], true]
11: primary_key_name = @options[:primary_key_name]
12: if primary_key_name == "dn"
13: old_value = dn_values_to_string_values(old_value)
14: end
15: current_value = @owner[primary_key_name, true]
16: current_value = dn_values_to_string_values(current_value)
17: new_value = old_value + current_value
18: new_value = new_value.uniq.sort
19: if old_value != new_value
20: entry[@options[:many]] = new_value
21: entry.save
22: end
23: end