# Rails: Problem with has\_and\_belongs\_to\_many

**URL:** <https://www.ruby-forum.com/t/rails-problem-with-has-and-belongs-to-many/128702>\
**Category:** Ruby\
**Created:** [February 10, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/rails-problem-with-has-and-belongs-to-many/128702 "2008-02-10T19:05:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felix\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c57346/32.png) [@Felix\_N](https://www.ruby-forum.com/u/Felix_N)\
**Post date:** [February 10, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/rails-problem-with-has-and-belongs-to-many/128702/1 "2008-02-10T19:05:42Z")

</div>

hello,

I have an m:n relationsship (has\_and\_belongs\_to\_many) between the models  
CoreUser and CoreGroup. So from some rails experience I thought I’d  
be able to add a (user,group)-relation simply by doing  
agroup.core\_users \<\< auser.

Unfortunately the following test-case fails on the last assertion  
(unless I include the line that is commented out):

def test\_add\_remove  
someuser = CoreUser.create!(:username =\> ‘test2s’, …)  
ag = CoreGroup.find\_by\_path("/Administrators")  
assert !ag.core\_users.include?(someuser)  
assert !someuser.core\_groups.include?(ag)

```
ag.core_users << someuser

```

# someuser.core\_groups \<\< ag

```
assert ag.core_users.include?(someuser)
assert someuser.core_groups.include?(ag)

```

end

Shouldn’t it work with the line being commented out (one direction)?

thanks,

---

<div class="post-metadata">

**Author:** ![Felix\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c57346/32.png) [@Felix\_N](https://www.ruby-forum.com/u/Felix_N)\
**Post date:** [February 10, 2008, 10:11pm UTC](https://www.ruby-forum.com/t/rails-problem-with-has-and-belongs-to-many/128702/2 "2008-02-10T22:11:57Z")

</div>

Felix N. wrote:

> hello,
> 
> I have an m:n relationsship (has\_and\_belongs\_to\_many) between the models

There’s a whole mailing list dedicated to Ruby on Rails and populated  
with people who love to discuss RoR. While there are some Rails-ers  
here, you’re going to get a lot more help on the RoR list. Find it here:

> **[Community](https://rubyonrails.org/community)**
>
> A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

---

<div class="post-metadata">

**Author:** ![Felix\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c57346/32.png) [@Felix\_N](https://www.ruby-forum.com/u/Felix_N)\
**Post date:** [February 11, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/rails-problem-with-has-and-belongs-to-many/128702/3 "2008-02-11T14:33:30Z")

</div>

Phlip wrote:

> Firstly, get on the Goole Ruby-on-Rails Talk forum. I know it’s a pain in  
> the nuts compared to USENET, but you need the best answers for these  
> questions.

It’s available as an NNTP feed on [news.gmane.org](http://news.gmane.org) as  
gmane.comp.lang.ruby.rails

Clifford H…

---

<div class="post-metadata">

**Author:** ![Felix\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c57346/32.png) [@Felix\_N](https://www.ruby-forum.com/u/Felix_N)\
**Post date:** [February 11, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/rails-problem-with-has-and-belongs-to-many/128702/4 "2008-02-11T14:52:57Z")

</div>

Phlip wrote:

> > It’s available as an NNTP feed on [news.gmane.org](http://news.gmane.org) as  
> > gmane.comp.lang.ruby.rails
> 
> And gmane reflects new posts properly back to the list??
> 
> The only time I ever tried that with GMain, to a Yahoo group, it didn’t  
> work, and I never tried again…

Yes, it bounces back a verification email the first time,  
and then it just works.
