David Chelimsky

random thoughtlessness

Cohesive Models

Now that Rails uses Ruby to express database structure (migrations), it seems silly to me that we can’t just express that right in the model classes. Something like this:

1
2
3
4
5
6
class Person < ActiveRecord::Base
  fields do |f|
    f.add :first_name, :string
    f.add :last_name, :string
  end
end

Doing this would not only make models more cohesive, but it would make it easier to specify a lot about models without ever touching the database.

We’d need a means of discovering necessary migrations on the fly, and that could get very tricky very quickly, but I think it’s worth exploring.