Sha256: 285b352ce2e18825480db9e7b1ee4a76b790c0d60845aba2d7207ce9f36de019

Contents?: true

Size: 905 Bytes

Versions: 2

Compression:

Stored size: 905 Bytes

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)
          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
        filter = "(#{primary_key}=#{@owner[@options[:foreign_key_name]]})"
        result = foreign_class.find(:all, :filter => filter, :limit => 1)
        raise EntryNotFound if result.empty?
        result.first
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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