module ActiveRecord #:nodoc: class Base class << self # Class methods private def construct_conditions_from_arguments(attribute_names, arguments) conditions = [] attribute_names.each_with_index do |name, idx| if fk = foreign_key_for(name) name = fk arguments[idx] = arguments[idx].id if arguments[idx].is_a?(ActiveRecord::Base) end conditions << "#{table_name}.#{connection.quote_column_name(name)} #{attribute_condition(arguments[idx])} " end [ conditions.join(" AND "), *arguments[0...attribute_names.length] ] end def construct_attributes_from_arguments(attribute_names, arguments) attributes = {} attribute_names.each_with_index do |name, idx| if fk = foreign_key_for(name) arguments[idx] = arguments[idx].id if arguments[idx].is_a?(ActiveRecord::Base) attributes[fk] = arguments[idx] else attributes[name] = arguments[idx] end end attributes end def all_attributes_exists?(attribute_names) attribute_names.all? do |name| column_methods_hash.include?(name.to_sym) || !foreign_key_for(name).nil? end end def foreign_key_for(name) if (ref = reflect_on_association(name.to_sym)) && ref.macro == :belongs_to ref.primary_key_name else nil end end end end end