Hi all, is there any way we can override the name of a join table? I''ve got 2 tables called "Location" and "Index" and the join table to link the two together is called "LocationIndex" instead of "location_index" like Rails expects it. I''ve even created a model for this join table and I can access its content fine but everytime it tries to use the join table, Rails comes up with the following error: Invalid object name ''location_index'', indeed the table is called "LocationIndex" PS: I''m working on a legacy database so I cannot change the name of the tables. PSS: Even if it means hacking the source I''m willing to look at it. I''ve tried myself to find out where in ActiveRecord this was taking place but I couldn''t find anything interesting. Gael _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hey Gael, I just learned this today! You want to take a look at http://api.rubyonrails.com - wealth of documentation. But in your model you want to add a line something like the following: In your Location model: has_and_belongs_to_many :indexes, :join_table => "LocationIndex" and in your Index model has_and_belongs_to_many :locations, :join_table => "LocationIndex" HTH, Mel On 12/12/05, Gael Pourriel <gael.pourriel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, is there any way we can override the name of a join table? > I''ve got 2 tables called "Location" and "Index" and the join table to link > the two together is called "LocationIndex" instead of "location_index" like > Rails expects it. > I''ve even created a model for this join table and I can access its content > fine but everytime it tries to use the join table, Rails comes up with the > following error: > > Invalid object name ''location_index'', indeed the table is called > "LocationIndex" > > PS: I''m working on a legacy database so I cannot change the name of the > tables. > PSS: Even if it means hacking the source I''m willing to look at it. I''ve > tried myself to find out where in ActiveRecord this was taking place but I > couldn''t find anything interesting. > > Gael > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks Mel, I''ve just found it too...I guess I was trigger happy posting on that one and I should have RTFM a bit more before. I was too busy diving in the source instead of just looking at Rdoc. This is great...Rail reminds me QT, whenever I wanted a feature it was there ready to be used... Gael On 12/12/05, Mel Riffe <mriffe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey Gael, > > I just learned this today! You want to take a look at > http://api.rubyonrails.com - wealth of documentation. But in your model > you want to add a line something like the following: > > In your Location model: > has_and_belongs_to_many :indexes, :join_table => "LocationIndex" > > and in your Index model > has_and_belongs_to_many :locations, :join_table => "LocationIndex" > > HTH, > > Mel > > > On 12/12/05, Gael Pourriel <gael.pourriel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi all, is there any way we can override the name of a join table? > > I''ve got 2 tables called "Location" and "Index" and the join table to > > link the two together is called "LocationIndex" instead of "location_index" > > like Rails expects it. > > I''ve even created a model for this join table and I can access its > > content fine but everytime it tries to use the join table, Rails comes up > > with the following error: > > > > Invalid object name ''location_index'', indeed the table is called > > "LocationIndex" > > > > PS: I''m working on a legacy database so I cannot change the name of the > > tables. > > PSS: Even if it means hacking the source I''m willing to look at it. I''ve > > tried myself to find out where in ActiveRecord this was taking place but I > > couldn''t find anything interesting. > > > > Gael > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Gael, try to add :join_table in your model, like: has_and_belongs_to_many :locations, :join_table => ''LocationIndex'' Nick Gael Pourriel wrote:> Hi all, is there any way we can override the name of a join table? > I''ve got 2 tables called "Location" and "Index" and the join table to > link > the two together is called "LocationIndex" instead of "location_index" > like > Rails expects it. > I''ve even created a model for this join table and I can access its > content > fine but everytime it tries to use the join table, Rails comes up with > the > following error: > > Invalid object name ''location_index'', indeed the table is called > "LocationIndex" > > PS: I''m working on a legacy database so I cannot change the name of the > tables. > PSS: Even if it means hacking the source I''m willing to look at it. I''ve > tried myself to find out where in ActiveRecord this was taking place but > I > couldn''t find anything interesting. > > Gael-- Posted via http://www.ruby-forum.com/.
should the join table not be called IndexLocation rather than LocationIndex? I thought rails gave trouble when the join table name is not built in alphabetical order. bruce On 12-Dec-05, at 2:01 PM, Nick Snels wrote:> Hi Gael, > > try to add :join_table in your model, like: > > has_and_belongs_to_many :locations, :join_table => ''LocationIndex'' > > Nick > > Gael Pourriel wrote: >> Hi all, is there any way we can override the name of a join table? >> I''ve got 2 tables called "Location" and "Index" and the join table to >> link >> the two together is called "LocationIndex" instead of >> "location_index" >> like >> Rails expects it. >> I''ve even created a model for this join table and I can access its >> content >> fine but everytime it tries to use the join table, Rails comes up >> with >> the >> following error: >> >> Invalid object name ''location_index'', indeed the table is called >> "LocationIndex" >> >> PS: I''m working on a legacy database so I cannot change the name >> of the >> tables. >> PSS: Even if it means hacking the source I''m willing to look at >> it. I''ve >> tried myself to find out where in ActiveRecord this was taking >> place but >> I >> couldn''t find anything interesting. >> >> Gael > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails