top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Do I Edit the Migration Too to Show the Belongs To

+1 vote
235 views

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?
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.

posted Jul 11, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
  1. 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.

  2. 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.

  3. 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.

answer Jul 11, 2013 by anonymous
Similar Questions
+2 votes

I am trying to write a simple calendar app and having troubles with time zones. For as many nice Date and Time helpers, action view and active record sure dont play nice with time zones.

I have an appointment model with the appointment_time attribute which is a datetime. My current issue is editing appointment_time with datetime_select within a form tag.

def appt_time
appointment_time.in_time_zone(time_zone) #this is the appointment owners time zone 
end

This gives a select with the current date and time in UTC, not the appointment date and time. appt_time does get called and returns the correct date and time adjusted for the time zone.

The docs mention nothing about time zones, what is the best way to accomplish this?

0 votes

I have a CentOS server which is part of an offline/private network. I need to install Ruby on Rails,
MySQL, Apache, and PHPmyAdmin on the server. Please help?

...