What you''re asking should be totally doable via Migrations. See
http://guides.rubyonrails.org/migrations.html.
Basically your flow should look something like:
1. Create stories table.
2. Add column chapters.story_id.
3. Find all chapters.
4. For each chapter:
- Find or create the matching story. (Find params will depend on
structure of story and chapter.)
- story.book = chapter.book
- chapter.story = story
- chapter.book = nil
5. Remove column chapters.book_id.
Could also write a one-off script to do this if you''re more
comfortable, but
leveraging ActiveRecord in this case will make life easier no matter where
you decide to implement it.
HTH.
On Wed, Apr 8, 2009 at 11:44 PM, Mike C
<snibble-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> I''ve decided to make a major change in my application which
affects
> more than 1 model. I don''t want to wipe all the data though.
Here''s
> the scenario I''m in:
>
> I have a Book model with a Chapter model. Book has many Chapters and
> Chapter belongs to Book. However, I want to add a Story model between
> them so that Book has many Stories and Stories has many Chapters. Is
> there a way I can make this change without wiping all my data?
> >
>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---