My Rails 3 has a user model and a profile model. User has_one Profile.
The profile currently has the attributes first_name and last_name . Although I'm not sure why you might want to change them, I initially assumed that they should be mutable, and so I put them in the profile model instead of the user model.
However, as the application evolved, I found that I really need the username and surname to not change, and that they really need them to be part of the User model instead of the profile model.
So, I was wondering if you can write a migration that:
- Add the
first_name and last_name to the user model. - Take the existing
first_name and last_name value for this user from the associated profile entry and copy it into the user model. - Remove the
first_name and last_name from the profile model as they are no longer needed.
So can this be done? Could you set an example? And, most importantly, are there any issues I should be aware of? I would like to apply this change to a production application, so it is important that I do not lose data when I make this change.
Thanks!
source share