On Apr 24, 2009, at 7:16 PM, djolley wrote:
> >> app/models/apple.rb: >> >> class Apple < ActiveRecord::Base >> set_table_name 'oranges' >> end > > I understand that I can set the table name from within the class. It > just seemed to me that, in addition to that, I would have to somehow > alert Rails to the fact that the model for the 'oranges' table was > contained in a file named 'apple.rb'. Otherwise, how would Rails know > to look for the Apple model in a file named apple.rb when the name of > the table is oranges? Put differently, I thought that by default, > Rails looked for the model in a file with a name which was the > singular of the table name. I don't see how I can tell it from within > a different file to look for that different file as it would have to > have found the different file to know that in the first place. Am I > making any sense? Do you see why I am confused? You're looking at it backwards... You're thinking this: database table -> rails -> model The reality is: rails -> model -> database table Rails will load up all of the files in app/models and assumes by default that there is a pluralized database table to go with each model. set_table_name changes that assumption. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---