Comic: Because ActiveRecord is Slow!
[Rails] Introducing Datamappify - ActiveRecord Without DB Migrations
Introduction
ActiveRecord is without doubt the de facto ORM library for Rails and many Ruby web frameworks. Many developers however, do not like database migrations and prefer to use DSL for data mapping. Datamappify is created with the sole purpose of getting rid of the DB migration headaches.
Why Not DB Migrations?
Well, depending on your specific project, DB migrations might create more trouble than it’s worth. Besides, your code is already version controlled, so why create a separate version control for your DB schema?
Why Not Use DataMapper, Sequel, etc?
As stated in the introduction, ActiveRecord is the most popular ORM in the rails community, it is actively developed and battle-tested. If your only grief with ActiveRecord is the DB migrations, why not just eliminate it be happy? ;)
[Rails Tip] Model Attributes Not Updating? `reset_column_information` To the Rescue!
So you were wondering why some of your model attributes weren’t updating properly? Well, it is perhaps because the db schema has changed but the changed schema has not been passed onto ActiveRecord, as is often the case in DB migration.
Taken from the ActiveRecord documentation:
Resets all the cached information about columns, which will cause them to be reloaded on the next request.
The most common usage pattern for this method is probably in a migration, when just after creating a table you want to populate it with some default values, eg:
class CreateJobLevels < ActiveRecord::Migration
def self.up
create_table :job_levels do |t|
t.integer :id
t.string :name
t.timestamps
end
JobLevel.reset_column_information
%w{assistant executive manager director}.each do |type|
JobLevel.create(:name => type)
end
end
def self.down
drop_table :job_levels
end
end