# ActiveLdap belongs\_to and has\_many associations

**URL:** <https://www.ruby-forum.com/t/activeldap-belongs-to-and-has-many-associations/158376>\
**Category:** Rails\
**Created:** [January 22, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/activeldap-belongs-to-and-has-many-associations/158376 "2009-01-22T17:41:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aebel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/838e76/32.png) [@aebel](https://www.ruby-forum.com/u/aebel)\
**Post date:** [January 22, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/activeldap-belongs-to-and-has-many-associations/158376/1 "2009-01-22T17:41:25Z")

</div>

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](http://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
