Ignore columns in a legacy database with ActiveRecord

4/07/2008

Add this to the model:

# prevent ActiveRecord stumbling on the column named 'hash' 
# by removing it from the column list
class << self # Class methods
   alias :all_columns :columns
 
   def columns
     all_columns.reject {|c| c.name == 'hash'}
   end
 end

Solution half-inched from:
http://groups.google.com/group/compositekeys/msg/202d04713ecbd6ee

No Comments

ActiveRecord: has the object been saved to the database yet?

25/06/2008

Cleaner than checking if the value of fruit.id is nil:

fruit.new_record?
No Comments