Forum: Ruby on Rails naming convention for bridge tables.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ddc850a63a423c3ff963bdf3a097652f?d=identicon&s=25 Larry Kelly (ldk2005)
on 2006-05-22 12:56
(Received via mailing list)
I read somewhere that the correct naming of bridge tables is in alpha
order.
For example.  I have two tables:
houses, and colors.

If I want to create a bridge table to associate colors with houses, I
would
name the table:

colors_houses

The associations work fine.

But, if I have a table named: track_houses.

Building a bridge table called: colors_track_houses, gives me model
associaton errors. How do I construct a bridge table where the table
names
contain multiple words?
118728039280884af9c112b05b543a50?d=identicon&s=25 unknown (Guest)
on 2006-05-22 13:14
(Received via mailing list)
Hello,

On Mon, May 22, 2006 at 03:56:34AM -0700, Larry Kelly wrote:
> Building a bridge table called: colors_track_houses, gives me model
> associaton errors. How do I construct a bridge table where the table names
> contain multiple words?

>From the doc of has_and_belongs_to_many:

:join_table - specify the name of the join table if the default based on
lexical order isnâ??t what you wan

so for example

class Color < ActiveRecord::Base
    has_and_belongs_to_many :track_houses, :join_table =>
"colors_track_houses"
end

--
Damien MERENNE   <dam@cosinux.org>
http://blog.cosinux.org/

In fine print on the last page of the Guinness Book of World Records
it notes that all world records are held by Chuck Norris,
and those listed in the book are simply the closest anyone else has ever
gotten.
D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2006-05-22 14:01
(Received via mailing list)
That's weird that you're getting errors. You shouldn't be. Are you
sure you changed all the model names (file names, class names and
habtm references) correctly?
-N
4034df6027cbecf3f4a19a711a248536?d=identicon&s=25 Steven Hansen (rooster)
on 2006-05-22 15:29
(Received via mailing list)
I beleive in this case, you need to do the following in the track_houses
model:

set_table_name('track_houses')
has_and_belongs_to_many :colors,
                                        :join_table =>
'colors_track_houses'


In the colors model do:

has_and_belongs_to_many :track_houses,
                                        :join_table =>
'colors_track_houses'
29b15f133c26b6dac0e4954d61733db9?d=identicon&s=25 Larry Kelly (Guest)
on 2006-05-22 17:06
(Received via mailing list)
Thanks for the help,
-Larry
This topic is locked and can not be replied to.