I made a mistake when making my first app. I did not use the: ruby script/generate model <modelname> method for creating my models. I more or less hand crafted each og them. Is there a way to go back so I get my db migration scripts to populate? -- Posted via http://www.ruby-forum.com/.
"Joe Cairns" <joe.cairns@gmail.com> wrote in message news:c27ab52d3c65fc197496fa0589e2438b@ruby-forum.com...>I made a mistake when making my first app. I did not use the: > ruby script/generate model <modelname> > > method for creating my models. I more or less hand crafted each og > them. Is there a way to go back so I get my db migration scripts to > populate? > > -- > Posted via http://www.ruby-forum.com/.just run script/generate model <modelname>. I''m pretty sure the generator won''t over-write existing files, so you''ll get test and migration files generated. Before you do, make a backup/commit your work - just in case :) if that doesn''t work, I''d just copy your model files outside of the models directory, run script/generate model and then copy the model files back hth
> > just run script/generate model <modelname>. I''m pretty sure the > generator > won''t over-write existing files, so you''ll get test and migration files > generated. Before you do, make a backup/commit your work - just in case > :) > > if that doesn''t work, I''d just copy your model files outside of the > models > directory, run script/generate model and then copy the model files back > > hthThat''s what I was doing, thanks! Just wanted to make sure there wasn''t a simple(r) way via rake or something. -- Posted via http://www.ruby-forum.com/.
Joe Cairns wrote:>what I was doing, thanks! Just wanted to make sure there wasn''t > a simple(r) way via rake or something.You could also leave the models and use ''script/generate migration'' There doesn''t need to be a one-to-one from model to migration. A. -- Posted via http://www.ruby-forum.com/.
Alan Francis wrote:> Joe Cairns wrote: >>what I was doing, thanks! Just wanted to make sure there wasn''t >> a simple(r) way via rake or something. > > You could also leave the models and use ''script/generate migration'' > There doesn''t need to be a one-to-one from model to migration. > > A.thanks! Here''s a follow-up questionon on models and tables: Should I keep a one for one correspondence of models to tables? For example, I have a couple of tables that I chose not to model - should I set up a very small model for those tables as placeholders? -- Posted via http://www.ruby-forum.com/.
If you want to access a table through ActiveRecord methods, you need to have a model. So the answer is almost certainly yes. Mind you, a model doesn''t have to have anything in it. A "blank" model like class Widget < ActiveRecord::Base end is sufficient to be able to work with all the fields in your table via ActiveRecord. It is also necessary. Joe Cairns wrote:> Alan Francis wrote: >> Joe Cairns wrote: >>>what I was doing, thanks! Just wanted to make sure there wasn''t >>> a simple(r) way via rake or something. >> >> You could also leave the models and use ''script/generate migration'' >> There doesn''t need to be a one-to-one from model to migration. >> >> A. > > thanks! > > Here''s a follow-up questionon on models and tables: > > Should I keep a one for one correspondence of models to tables? For > example, I have a couple of tables that I chose not to model - should I > set up a very small model for those tables as placeholders?-- Posted via http://www.ruby-forum.com/.