On 11 July 2013 06:55, Peter
<peter-I8Khkwz7QpbQT0dZR+AlfA@public.gmane.org>
wrote:> Hi Everyone,
>
> Do I edit the corresponding migration also to show the belongs_to (and the
> has_many)? I have a many to many relationship where I am using the
"has_many
> :through" association. When I place in the individual classes the
''has_many
> :through'' and the ''belongs_to'' associations, do
I also edit the
> corresponding migrations to reflect those changes?
No, there is no need to change the existing migrations. The
relationship declarations (has_many and so on) have not direct effect
on the database contents, they just tell Rails what to expect in the
database.
>
> I would like those changes to be reflected in the database also, but I
don''t
> know whether there was a way to run one of the migration generator commands
> that would have included these associations.
>
> Also, I have already run the migration so is there a way to create a new
> migration that would simply add these associations? I would prefer not to
> edit existing migrations.
Whenever you make a change to the database use a new migration. You
will just get yourself (and likely the database) very confused if you
try to add to an existing migration.
>
> Thank you in advance for the advice. I''m very new to Rails and am
just
> learning it with a toy application I''m building.
Work right through a good tutorial such as railstutorial.org (which is
free to use online) before starting you own experiments. That will
show you the basics of Rails.
Colin
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuc4_t-AaPd9Ge6VPuPt1edeB6AYoL57iAKRjufwvXHpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.