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?
on 2006-05-22 14:56
on 2006-05-22 15:14
Hello, On Mon, May 22, 2006 at 03:56:34AM -0700, Larry K. 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 <email@example.com> 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.
on 2006-05-22 16:01
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
on 2006-05-22 17:29
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'
on 2006-05-22 19:06
Thanks for the help, -Larry