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? -- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060522/911b8446/attachment.html
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.
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 22/05/06, Larry Kelly <ldk2005@gmail.com> wrote:> 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? > > > -- > Best Regards, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
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'' njmacinnes@gmail.com wrote:> 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 22/05/06, Larry Kelly <ldk2005@gmail.com> wrote: > >> 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? >> >> >> -- >> Best Regards, >> -Larry >> "Work, work, work...there is no satisfactory alternative." >> --- E.Taft Benson >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for the help, -Larry On 5/22/06, Steven Hansen <runner@berkeley.edu> wrote:> > > 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'' > > > njmacinnes@gmail.com wrote: > > > 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 22/05/06, Larry Kelly <ldk2005@gmail.com> wrote: > > > >> 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? > >> > >> > >> -- > >> Best Regards, > >> -Larry > >> "Work, work, work...there is no satisfactory alternative." > >> --- E.Taft Benson > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060522/8dd685c9/attachment.html