|
Jeff Williams wrote this in comment 16 at...http://www.slash7.com/articles/2005/01/24/really-getting-started- in-rails
If you don’t have the benefit of getting to make well designed tables with sensible naming conventions, but instead have to deal with a database mess you have inherited, the following things can be helpful…If you want to make a ‘Story’ ActiveRecord, but your table is not called ‘stories’ (but ‘story’ or worse…), then you can override the table name in the model using:def self.table_name() “strange_table_name” end The same thing applies for the table’s auto increment id column: def self.primary_key() “strange_id_name” end Also, when defining foreign keys the ‘foreign_key’ option can be used: belongs_to :author, :foreign_key => “not_author_id”
From what have seen at this point, looks like once you've done this in your model class, the overridden table can be handled just like one that follows the convention.
Might not be able to use the scaffold with it, but those get replaced when an app is built out anyway, so actual controller, etc. just get generated sooner.
thx & hth, --Jerome
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.