Forum: Ruby on Rails ActiveLdap belongs_to and has_many associations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fa82c422486be83532c7016111d6e11b?d=identicon&s=25 Alexander Ebel (aebel)
on 2009-01-22 17:41
Hi,
I am trying to use ActiveLdap for authentication in my rails app. But I
am running into a problem with the "belongs_to" and "has_many"
associations.

Here ist how my models look like.

class Person < ActiveLdap::Base
  ldap_mapping :dn_attribute => "uid",
               :prefix => "ou=People",
               :classes => ['top', 'account', 'posixAccount']
  belongs_to :groups, :class => 'Group', :many => 'memberUid'
end

class Group < ActiveLdap::Base
  ldap_mapping :dn_attribute => "cn",
                            :prefix => "ou=Group",
                            :classes => ['posixGroup','top']
  has_many :member, :class => "Person", :wrap => "memberUid"
end

According to ActiveLdap documentation I am testing the association.

irb> me = User.find('aebel')
irb> me.groups.each { |group| p group.cn };nil
"develop"
"wheel"
=> nil

So far everything works fine. But when I try to do a membership test, it
fails.

irb> me.groups.member? 'wheel'
=> false

My environment:
Rails 2.2.2
AciveLdap SVN revision 802

Any help will be appreciated
Alexander Ebel
This topic is locked and can not be replied to.