# Newbie belongs\_to question

**URL:** <https://www.ruby-forum.com/t/newbie-belongs-to-question/181074>\
**Category:** Rails\
**Created:** [January 5, 2010, 2:47am UTC](https://www.ruby-forum.com/t/newbie-belongs-to-question/181074 "2010-01-05T02:47:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@asoto](https://www.ruby-forum.com/u/asoto)\
**Post date:** [January 5, 2010, 2:47am UTC](https://www.ruby-forum.com/t/newbie-belongs-to-question/181074/1 "2010-01-05T02:47:52Z")

</div>

Hey so all of the articles I read on this say that if you’re going to  
have two belong\_to’s to a single table ti should look something like  
this

belongs\_to :player, :foreign\_key =\> “player\_one”  
belongs\_to :opponent, :class\_name =\> “Player”, :foreign\_key =\>  
“player\_two”

That seems to work okay and I can access the first “player” on the view  
with object.player.whatever, but I have no idea how to access the second  
object.

I thought it would be object.opponent.whatever but that doesn’t work.

---

<div class="post-metadata">

**Author:** ![asoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@asoto](https://www.ruby-forum.com/u/asoto)\
**Post date:** [January 5, 2010, 3:00am UTC](https://www.ruby-forum.com/t/newbie-belongs-to-question/181074/2 "2010-01-05T03:00:57Z")

</div>

Never mind! I was using an invalid ID which is why it never showed a  
value.
