[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rails: Problem with has_and_belongs_to_many

Felix Natter

2/10/2008 6:02:00 PM

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,

--
Felix Natter
6 Answers

Phlip

2/10/2008 6:11:00 PM

0

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.

> ag.core_users << someuser
> # someuser.core_groups << ag

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

The Joy of ActiveRecord is you only define relations once, then use them
everywhere. However, your code sample does not contain the definitions -
only the usage. Please post your class declarations to the Rails group, for
the best answer!

--
Phlip


Clifford Heath

2/10/2008 8:27:00 PM

0

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 as gmane.comp.lang.ruby.rails

Clifford Heath.

Phlip

2/10/2008 8:37:00 PM

0

> It's available as an NNTP feed on 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...


Clifford Heath

2/10/2008 8:47:00 PM

0

Phlip wrote:
>> It's available as an NNTP feed on 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.

Tim Hunter

2/10/2008 9:11:00 PM

0

Felix Natter 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:
http://www.rubyonrails.com...


--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

Phlip

2/10/2008 9:33:00 PM

0

> There's a whole mailing list dedicated to Ruby on Rails...

I'm aware this newsgroup has a Rails problem, but this poster was already
_successfully_ diverted there. Please be careful with that rubber stamp, hm?