# Multiple HABTM to one table

**URL:** <https://www.ruby-forum.com/t/multiple-habtm-to-one-table/70524>\
**Category:** Rails\
**Created:** [February 19, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/multiple-habtm-to-one-table/70524 "2006-02-19T18:26:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [February 19, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/multiple-habtm-to-one-table/70524/1 "2006-02-19T18:26:53Z")

</div>

I have a class Player, and a class Game.

Game has two HABTM relationships to the Player table through seperate  
relationship tables.

class Game \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :players, :uniq =\> true  
has\_and\_belongs\_to\_many :victors, :class\_name =\> ‘Player’, :uniq =\>  
true  
end

When I add Player A to players, and Player B to victors, and save the  
game,  
there is no INSERT for games\_victors, but there is for games\_players. I  
cannot figure out why this is so.

Furthermore, when I load the game, there are two SELECTs with JOINS to  
GAMES\_PLAYERS, instead of one for GAMES\_PLAYERS and one for  
GAMES\_VICTORS.

What have I done wrong?

David

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [February 19, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/multiple-habtm-to-one-table/70524/2 "2006-02-19T20:52:36Z")

</div>

Further investigation shows that at least part of this has been fixed  
(Changeset #3331) in the TRUNK version. What’s the best way to run a  
Rails  
app with a version from subversion?

David

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [February 19, 2006, 9:10pm UTC](https://www.ruby-forum.com/t/multiple-habtm-to-one-table/70524/3 "2006-02-19T21:10:52Z")

</div>

On Feb 19, 2006, at 7:38 AM, David C. wrote:

> Further investigation shows that at least part of this has been fixed  
> (Changeset #3331) in the TRUNK version. What’s the best way to  
> run a Rails  
> app with a version from subversion?

Checkout Rails from svn into the vendors directory of the application  
and then keep it up to date though out the development of the  
project, freezing the Rails checkout on launch. We just had a q & a  
session with DHH and this is how 37Signals develops their apps.

–  
Jason P.  
removed\_email\_address@domain.invalid

“The computer allows you to make mistakes  
faster than any other invention, with the  
possible exception of handguns and tequila.”

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [February 19, 2006, 11:33pm UTC](https://www.ruby-forum.com/t/multiple-habtm-to-one-table/70524/4 "2006-02-19T23:33:10Z")

</div>

On Sunday 19 February 2006 09:08 am, David C. wrote:

> On Sunday 19 February 2006 08:38 am, David C. wrote:
> 
> > Further investigation shows that at least part of this has been fixed  
> > (Changeset #3331) in the TRUNK version. What’s the best way to run a  
> > Rails app with a version from subversion?
> 
> OK. Even running with the trunk version, I’m having a problem. I get  
> three INSERTs total, one for GAME, and two for GAMES\_PLAYERS, but none for  
> GAMES\_VICTORS.

For the record, this one was in my code. I need to specify the  
join\_table on  
the second HABTM. Of course, I blame the documentation for not  
discussing  
the default. I’ve submitted a patch for it.

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [February 19, 2006, 9:22pm UTC](https://www.ruby-forum.com/t/multiple-habtm-to-one-table/70524/5 "2006-02-19T21:22:58Z")

</div>

On Sunday 19 February 2006 08:38 am, David C. wrote:

> Further investigation shows that at least part of this has been fixed  
> (Changeset #3331) in the TRUNK version. What’s the best way to run a  
> Rails app with a version from subversion?

OK. Even running with the trunk version, I’m having a problem. I get  
three  
INSERTs total, one for GAME, and two for GAMES\_PLAYERS, but none for  
GAMES\_VICTORS.
