Sha256: 2f0f302aef668707b174e256cbfd6713b08f5ec7b79435c06fd1ac71f87538a5

Contents?: true

Size: 1.14 KB

Versions: 44

Compression:

Stored size: 1.14 KB

Contents

require 'active_ldap/association/proxy'

module ActiveLdap
  module Association
    class BelongsTo < Proxy
      def replace(entry)
        if entry.nil?
          @target = @owner[@options[:foreign_key_name]] = nil
        else
          @target = (Proxy === entry ? entry.target : entry)
          infect_connection(@target)
          unless entry.new_entry?
            @owner[@options[:foreign_key_name]] = entry[primary_key]
          end
          @updated = true
        end

        loaded
        entry
      end

      def updated?
        @updated
      end

      private
      def have_foreign_key?
        not @owner[@options[:foreign_key_name]].nil?
      end

      def find_target
        value = @owner[@options[:foreign_key_name]]
        raise EntryNotFound if value.nil?
        key = primary_key
        if key == "dn"
          result = foreign_class.find(value, find_options)
        else
          filter = {key => value}
          options = find_options(:filter => filter, :limit => 1)
          result = foreign_class.find(:all, options).first
        end
        raise EntryNotFound if result.nil?
        result
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 4 rubygems

Version Path
activeldap-7.2.1 lib/active_ldap/association/belongs_to.rb
activeldap-7.2.0 lib/active_ldap/association/belongs_to.rb
activeldap-7.0.0 lib/active_ldap/association/belongs_to.rb
activeldap-6.1.0 lib/active_ldap/association/belongs_to.rb
activeldap-6.0.4 lib/active_ldap/association/belongs_to.rb
activeldap-6.0.3 lib/active_ldap/association/belongs_to.rb
activeldap-6.0.2 lib/active_ldap/association/belongs_to.rb
activeldap-6.0.1 lib/active_ldap/association/belongs_to.rb
activeldap-6.0.0 lib/active_ldap/association/belongs_to.rb
activeldap-5.2.4 lib/active_ldap/association/belongs_to.rb
activeldap-5.2.3 lib/active_ldap/association/belongs_to.rb
activeldap-5.2.2 lib/active_ldap/association/belongs_to.rb
activeldap-5.2.1 lib/active_ldap/association/belongs_to.rb
activeldap-5.2.0 lib/active_ldap/association/belongs_to.rb
activeldap-5.1.1 lib/active_ldap/association/belongs_to.rb
activeldap-5.1.0 lib/active_ldap/association/belongs_to.rb
activeldap-3.2.3 lib/active_ldap/association/belongs_to.rb
powerhome-activeldap-3.2.3 lib/active_ldap/association/belongs_to.rb
activeldap-4.0.6 lib/active_ldap/association/belongs_to.rb
activeldap-4.0.5 lib/active_ldap/association/belongs_to.rb