Show
Ignore:
Timestamp:
10/11/07 20:17:12 (1 year ago)
Author:
jarmo
Message:
  • Adds the Customer type
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/active_record_patch.rb

    r668 r707  
    3131          value.gsub('%', '%25').gsub("\0", '%00') 
    3232        end 
    33          
     33 
    3434        def binary_to_string(value) 
    3535          value.gsub('%00', "\0").gsub('%25', '%') 
     
    4141 
    4242# Patch to ActiveRecord::ConnectionAdapters::SqliteAdapter#add_column 
    43 # Fixed a bug that made add_column to raise an error when called  
    44 # inside a transaction. The error was caused by the execution of  
     43# Fixed a bug that made add_column to raise an error when called 
     44# inside a transaction. The error was caused by the execution of 
    4545# 'VACUUM', which can't be called when there is an active transaction. 
    4646# This may break sqlite versions piror to 3.1.3. 
     
    5353      end 
    5454    end 
    55       
     55 
    5656    # Overwrite add_column so that it only executes 'VACUUM' if there are 
    5757    # no active transactions. 
     
    7373    class PostgreSQLAdapter 
    7474      alias_method :quote_old, :quote 
    75        
     75 
    7676      def quote(value, column = nil) 
    7777        result = quote_old(value, column) 
     
    8484  end 
    8585end 
     86 
     87# Patch to ActiveRecord::Validations::ClassMethods#validates_uniqueness_of. 
     88# Makes the uniqueness validation work correctly with Single Table Inheritance. 
     89# See the Rails Trac: http://dev.rubyonrails.org/ticket/3833 
     90module ActiveRecord 
     91  module Validations 
     92    module ClassMethods 
     93      def validates_uniqueness_of(*attr_names) 
     94        configuration = { :message => ActiveRecord::Errors.default_error_messages[:taken], :case_sensitive => true } 
     95        configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) 
     96 
     97        validates_each(attr_names,configuration) do |record, attr_name, value| 
     98          if value.nil? || (configuration[:case_sensitive] || !columns_hash[attr_name.to_s].text?) 
     99            condition_sql = "#{record.class.table_name}.#{attr_name} #{attribute_condition(value)}" 
     100            condition_params = [value] 
     101          else 
     102            condition_sql = "LOWER(#{record.class.table_name}.#{attr_name}) #{attribute_condition(value)}" 
     103            condition_params = [value.downcase] 
     104          end 
     105          if scope = configuration[:scope] 
     106            Array(scope).map do |scope_item| 
     107              scope_value = record.send(scope_item) 
     108              condition_sql << " AND #{record.class.table_name}.#{scope_item} #{attribute_condition(scope_value)}" 
     109              condition_params << scope_value 
     110            end 
     111          end 
     112          unless record.new_record? 
     113            condition_sql << " AND #{record.class.table_name}.#{record.class.primary_key} <> ?" 
     114            condition_params << record.send(:id) 
     115          end 
     116          if self.find(:first, :conditions => [condition_sql, *condition_params]) 
     117            record.errors.add(attr_name, configuration[:message]) 
     118          end 
     119        end 
     120      end 
     121    end 
     122  end 
     123end 

© 2004-2007 Norfello Oy All Rights Reserved