Yes, i'm sorry .. examples.. anyway: declaring fields in models should not be 
mandatory! To keep track of renaming, changing and deleting of columns is 
already up to the migration system. We could think to a rake task to check if 
everything is up-to-date.. (few line of code) but i don't care too much of it 
because i think such kind of changes are something that is better to do by hand.

The generative approach is something that is needed only for the 
non-destructive changes (adding column, tables and indexes) IMO. Also you 
should see the generator for what it is: just something that can write for you 
something that you should write by yourself otherwise.

But here is an example of what misses the migration-alone approach:

# paperclip_schema gem:

module PaperclipSchema
  extend ActiveSupport::Concern

  module ClassMethods

    def has_attached(name, options = {})

      has_attached_file(name, options)
      
      field :"#{name}_file_name"
      field :"#{name}_content_type"
      field :"#{name}_file_size", :as => :integer
      field :"#{name}_updated_at", :as => :datetime

   end
 
  end
end
 
ActiveRecord::Base.send :include, PaperclipSchema
# ~ 

Application models:

class Picture
   has_attached("image")
end

class User
  has_attached("avatar")
end

now generate migrations, and enjoy using Paperclip (again this is just an very 
simple example).. 

Application Logic is not aware of what happens below and it seems correct to 
me. How can't you see this is a level of abstraction we don't have now? 

As a counterevidence: how much time will you need to port your code to another 
ORM.. such as DataMapper.. or switch from DM to ActiveRecord, or even MongoId 
(supposing you wish also to change database)? This way they would be almost 
interchangeable.

Rails is trying to move to an ORM agnostic model or em i missing something? 
Well this is a way to make ActiveRecord play nice in the ORM agnostic world.








-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to