Hi, If I change my db tables after using the generate script does rails know the db has changed? Does rails check the db every time it runs when in development mode? What if I have already done a bunch of coding in my model corresponding to the table. Do I have to cut and paste that? Thanks, Peter
On Sun, Oct 30, 2005 at 08:23:04PM -0800, Peter Michaux wrote:> If I change my db tables after using the generate script does rails > know the db has changed? Does rails check the db every time it runs > when in development mode? What if I have already done a bunch of coding > in my model corresponding to the table. Do I have to cut and paste > that?If your model names get out of sync with your table names you can always override ActiveRecord''s inferance of the corresponding table name by using set_table_name. e.g. class Octopus < ActiveRecord::Base set_table_name ''loci'' end Or you can rename your model class (class name and file name) as well as the corresponding fixture file. marcel -- Marcel Molina Jr. <marcel-WRrfy3IlpWYdnm+yROfE0A@public.gmane.org>
On 30-Oct-05, at 8:32 PM, Marcel Molina Jr. wrote:> On Sun, Oct 30, 2005 at 08:23:04PM -0800, Peter Michaux wrote: >> If I change my db tables after using the generate script does rails >> know the db has changed? Does rails check the db every time it runs >> when in development mode? What if I have already done a bunch of >> coding >> in my model corresponding to the table. Do I have to cut and paste >> that? > > If your model names get out of sync with your table names you can > always > override ActiveRecord''s inferance of the corresponding table name by > using > set_table_name.Thanks but Oops. I wasn''t clear enough. I didn''t mean changing table names. By change the tables I meant if I added fields to a particular table. How will the model know those new fields exist. Peter
Peter Michaux wrote:> > On 30-Oct-05, at 8:32 PM, Marcel Molina Jr. wrote: > >> On Sun, Oct 30, 2005 at 08:23:04PM -0800, Peter Michaux wrote: >> >>> If I change my db tables after using the generate script does rails >>> know the db has changed? Does rails check the db every time it runs >>> when in development mode? What if I have already done a bunch of coding >>> in my model corresponding to the table. Do I have to cut and paste >>> that? >> >> >> If your model names get out of sync with your table names you can always >> override ActiveRecord''s inferance of the corresponding table name by >> using >> set_table_name. > > > Thanks but Oops. I wasn''t clear enough. I didn''t mean changing table > names. By change the tables I meant if I added fields to a particular > table. How will the model know those new fields exist.Which generate script are you refering to? The model, controller or scaffold generator? Regards, Blair -- Blair Zajac, Ph.D. <blair-szbw9MROnEZWk0Htik3J/w@public.gmane.org> Subversion and Orca training and consulting http://www.orcaware.com/svn/
On Sun, Oct 30, 2005 at 08:38:32PM -0800, Peter Michaux wrote:> > On 30-Oct-05, at 8:32 PM, Marcel Molina Jr. wrote: > > >On Sun, Oct 30, 2005 at 08:23:04PM -0800, Peter Michaux wrote: > >>If I change my db tables after using the generate script does rails > >>know the db has changed? Does rails check the db every time it runs > >>when in development mode? What if I have already done a bunch of > >>coding > >>in my model corresponding to the table. Do I have to cut and paste > >>that? > > > >If your model names get out of sync with your table names you can > >always > >override ActiveRecord''s inferance of the corresponding table name by > >using > >set_table_name. > > Thanks but Oops. I wasn''t clear enough. I didn''t mean changing table > names. By change the tables I meant if I added fields to a particular > table. How will the model know those new fields exist.ActiveRecord introspects your table''s structure automatically for you. Add and delete columns with impunity. marcel -- Marcel Molina Jr. <marcel-WRrfy3IlpWYdnm+yROfE0A@public.gmane.org>