module ActiveLdap::Associations::ClassMethods

def belongs_to(association_id, options={})


:primary_key => "gidNumber" # Group#gidNumber
:foreign_key => "gidNumber", # User#gidNumber
belongs_to :primary_group, :class_name => "Group",
# dn attribute value is used by default
## :foreign_key => "uid" # User#uid
## deprecated since 1.1.0. Use :primary_key instead.
# :primary_key => "uid" # User#uid
:many => "memberUid" # Group#memberUid
belongs_to :groups, :class_name => "Group",
Example:

|:class_name|.
|:foreign_key| in the other LDAP entry covered by class
attribute value on to multiple items which reference it by
This defines a method for an extension class map its DN key

belongs_to
def belongs_to(association_id, options={})
  validate_belongs_to_options(options)
  klass = options[:class]
  klass ||= (options[:class_name] || association_id.to_s).classify
  foreign_key = options[:foreign_key]
  primary_key = options[:primary_key]
  many = options[:many]
  set_associated_class(association_id, klass)
  opts = {
    :association_id => association_id,
    :foreign_key_name => foreign_key,
    :primary_key_name => primary_key,
    :many => many,
    :extend => options[:extend],
  }
  if opts[:many]
    association_class = Association::BelongsToMany
    foreign_key_name = opts[:foreign_key_name]
    if foreign_key_name
      message = _(":foreign_key belongs_to(:many) option is " \
                  "deprecated since 1.1.0. Use :primary_key instead.")
      ActiveLdap.deprecator.warn(message)
      opts[:primary_key_name] ||= foreign_key_name
    end
    opts[:primary_key_name] ||= dn_attribute
  else
    association_class = Association::BelongsTo
    opts[:foreign_key_name] ||= "#{association_id}_id"
    before_save do
      if instance_variable_defined?(:"@#{association_id}")
        association = instance_variable_get(:"@#{association_id}")
        if association and association.updated?
          self[association.__send__(:primary_key)] =
            association[opts[:foreign_key_name]]
        end
      end
    end
  end
  association_accessor(association_id) do |target|
    association_class.new(target, opts)
  end
end