# Has\_and\_belongs\_to\_many - Access to Linkingtable

**URL:** <https://www.ruby-forum.com/t/has-and-belongs-to-many-access-to-linkingtable/121282>\
**Category:** Rails\
**Created:** [November 26, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-access-to-linkingtable/121282 "2007-11-26T13:24:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lpp-rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b5e925/32.png) [@lpp-rob](https://www.ruby-forum.com/u/lpp-rob)\
**Post date:** [November 26, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-access-to-linkingtable/121282/1 "2007-11-26T13:24:27Z")

</div>

Hello,

i just don’t get how to refer and edit the automaticly generated table  
by has\_many\_belongs\_to\_many (n:m) relation.

Here are my basics (shortend):

class Country \< ActiveRecord::Base

has\_and\_belongs\_to\_many :regions

end

class Region \< ActiveRecord::Base

has\_and\_belongs\_to\_many :countries

end

So now rails creates a new table countries\_regions in the db. how can i  
access the information out of this table. E.g. i want to know the region  
of a specific country (by id). Lets say the country belongs to 2 regions  
(Europe, Asia).

thanks rob

---

<div class="post-metadata">

**Author:** ![lpp-rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b5e925/32.png) [@lpp-rob](https://www.ruby-forum.com/u/lpp-rob)\
**Post date:** [November 26, 2007, 1:49pm UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-access-to-linkingtable/121282/2 "2007-11-26T13:49:14Z")

</div>

find country with id 12:

@country = Country.find(12)

then access it’s regions with:  
@country.regions
