# Question about has\_many/belongs\_to

**URL:** <https://www.ruby-forum.com/t/question-about-has-many-belongs-to/88274>\
**Category:** Rails\
**Created:** [March 9, 2007, 10:28am UTC](https://www.ruby-forum.com/t/question-about-has-many-belongs-to/88274 "2007-03-09T10:28:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven\_Magnus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sven\_Magnus](https://www.ruby-forum.com/u/Sven_Magnus)\
**Post date:** [March 9, 2007, 10:28am UTC](https://www.ruby-forum.com/t/question-about-has-many-belongs-to/88274/1 "2007-03-09T10:28:27Z")

</div>

Hi,

In the firm I work, we’re disabling table name pluralization because  
this complies to our standards.

So, suppose I have a table client and a table contact\_person (which  
has a client\_id). I also have the models Client and ContactPerson for  
these.

In my Client class, I would have :

has\_many :contact\_person

and in the ContactPerson class I would have

belongs\_to :client

Is this correct? Or do I need to pluralize has\_many :contact\_person?

Also, how do I get the collection of the ContactPersons associated to  
a specific Client object? I tried @client.contactPersons and  
@client.contactPeople, but neither seems to work.

I know this is all basic stuff, but I’m still trying to get my head  
around ruby/rails.

Thanks for your time,

Sven Magnus

---

<div class="post-metadata">

**Author:** ![Sven\_Magnus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sven\_Magnus](https://www.ruby-forum.com/u/Sven_Magnus)\
**Post date:** [March 9, 2007, 4:26pm UTC](https://www.ruby-forum.com/t/question-about-has-many-belongs-to/88274/2 "2007-03-09T16:26:24Z")

</div>

In your Client class, you should have

has\_many :contact\_people

Be sure to implicitly specify the table names in the Client and  
ContactPerson models using set\_table\_name; otherwise, Rails will look  
for “clients” and “contact\_people” in your database.

If you already have a collection of contact\_people (an array), you could  
do:

client.contact\_people = my\_collection

Rails tends to use underscores instead of camel case. You might want to  
take a look at the associations documentation in the API - there are  
good explanations of these concepts there.
