Just looking to see if anyone has a preferred method for handling ActiveRecord class updates when performing database migrations.
For example I just created a migration that adds a bunch of fields to a table. But now I have to kind of "manually" remember to update the actual ActiveRecord classes to include the new fields.
Its even worse in a way when I’m altering existing columns of a table because I may have to “remember” to change the maximum length , name of column etc…
And if I ever have to back out a migration — ooooh boy. Now I have to remember to undo all of the changes to each of the ActiveRecord classes I’ve modified.
So just wanted to know if anyone has a method for handling these types of scenarios.
Usually you’re committing you changes to a version control system. Typically a commit contains both migration and AR changes. So when reverting you’re first reverting migration and then reverting a commit.
You could also inherit your models from a base model and then use Gii to update the base models whenever the schema changes.
However, I prefer to do that manually because I don’t make extensive changes to my models - I prefer to edit my model(s) to match the migration each time I create a new one.
And then, as Samdark said, let source control handle history.