# Model association

**URL:** <https://www.ruby-forum.com/t/model-association/234408>\
**Category:** Rails\
**Created:** [March 2, 2015, 9:49pm UTC](https://www.ruby-forum.com/t/model-association/234408 "2015-03-02T21:49:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [March 2, 2015, 9:49pm UTC](https://www.ruby-forum.com/t/model-association/234408/1 "2015-03-02T21:49:00Z")

</div>

Hi,  
I’ve generated 2 models (Player and Trainer) with the “generate  
scaffold”  
command with the following tables:  
_Player_  
name:string  
last\_name:string  
trainer:string  
team:string

_Trainer_  
name:string  
last\_name:string  
phone\_number:string  
team:string

I’ve set the association in the Player model class (belongs\_to :trainer)  
and in the Trainer model class (has\_many :player).  
How to make this relationship effective? Should I just type rails  
generate  
migration ? Should I add some arguments?  
I want the trainer to be connected to the player . Thank you for your  
assitance. I really appreciate.  
Sandro

---

<div class="post-metadata">

**Author:** ![Palmo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@Palmo](https://www.ruby-forum.com/u/Palmo)\
**Post date:** [March 2, 2015, 10:30pm UTC](https://www.ruby-forum.com/t/model-association/234408/2 "2015-03-02T22:30:10Z")

</div>

On 2 March 2015 at 17:24, Palmo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> name:string  
> last\_name:string  
> phone\_number:string  
> team:string
> 
> I’ve set the association in the Player model class (belongs\_to :trainer) and  
> in the Trainer model class (has\_many :player).  
> How to make this relationship effective? Should I just type rails generate  
> migration ? Should I add some arguments?  
> I want the trainer to be connected to the player . Thank you for your  
> assitance. I really appreciate.

Rather than answering your question I am going to suggest you start by  
working right through a good tutorial such as [railstutorial.org](http://railstutorial.org) (which  
is free to use online) including doing all the exercises. That will  
show you the basics of rails. The time spent will be very rapidly  
recovered.

Part of the reason for not answering the question is that once you  
have worked through the tutorial I expect you will see that you are  
not asking the right question. 🙂

Colin

---

<div class="post-metadata">

**Author:** ![Palmo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@Palmo](https://www.ruby-forum.com/u/Palmo)\
**Post date:** [March 5, 2015, 7:36am UTC](https://www.ruby-forum.com/t/model-association/234408/3 "2015-03-05T07:36:26Z")

</div>

I would say, Colin has given a sound advise. Do take a look at  
Activerecord  
Associations [http://guides.rubyonrails.org/association\_basics.html](http://guides.rubyonrails.org/association_basics.html) and  
other railsguides pages. They are really great!

Vineeth

---

<div class="post-metadata">

**Author:** ![Palmo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@Palmo](https://www.ruby-forum.com/u/Palmo)\
**Post date:** [March 3, 2015, 6:21pm UTC](https://www.ruby-forum.com/t/model-association/234408/4 "2015-03-03T18:21:48Z")

</div>

Hi Sandro, should it be “has\_many :players” instead?

If it is many I believe the convention is plural? Then it should work! I  
believe!

Cheers,

Julio

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Palmo  
Sent: Monday, March 2, 2015 6:24 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Rails] model association

Hi,

I’ve generated 2 models (Player and Trainer) with the “generate  
scaffold” command with the following tables:

Player

name:string

last\_name:string

trainer:string

team:string

Trainer

name:string

last\_name:string

phone\_number:string

team:string

I’ve set the association in the Player model class (belongs\_to :trainer)  
and in the Trainer model class (has\_many :player).

How to make this relationship effective? Should I just type rails  
generate migration ? Should I add some arguments?

I want the trainer to be connected to the player . Thank you for your  
assitance. I really appreciate.

Sandro

–  
You received this message because you are subscribed to the Google  
Groups “Ruby on Rails: Talk” group.  
To unsubscribe from this group and stop receiving emails from it, send  
an email to removed\_email\_address@domain.invalid  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) .  
To post to this group, send email to removed\_email\_address@domain.invalid  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) .  
To view this discussion on the web visit  
[https://groups.google.com/d/msgid/rubyonrails-talk/2ab7d242-497b-4acc-82e6-e37c822641d7%40googlegroups.com](https://groups.google.com/d/msgid/rubyonrails-talk/2ab7d242-497b-4acc-82e6-e37c822641d7%40googlegroups.com)  
[https://groups.google.com/d/msgid/rubyonrails-talk/2ab7d242-497b-4acc-82e6-e37c822641d7%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/rubyonrails-talk/2ab7d242-497b-4acc-82e6-e37c822641d7%40googlegroups.com?utm_medium=email&utm_source=footer)  
.  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
