Sha256: 16920e78e59240b5c4303b188488d53d95a7cf4958efded9e710655aac5c9589
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
# -*- coding: utf-8 -*- require "custom-active-record/sjis-base" module ActiveRecord class PluralsPKeysBase < ActiveRecord::SJISBase @@primary_key_list = {} def self.set_primary_key_list(*keys) @@primary_key_list[self] = keys.to_mssql_encode end def destroy unless new_record? where = "" first = true primary_key_list.each do |key| value = read_attribute(key) where << " and " unless first where << " [#{key}] = #{quote_value(value)}" first = false end connection.delete <<-end_sql, "#{self.class.name} Destroy" DELETE FROM #{self.class.table_name} WHERE #{where} end_sql end freeze end private def primary_key_list return @@primary_key_list[self.class] end def update where = "" first = true primary_key_list.each do |key| value = read_attribute(key) where << " and " unless first where << "[#{key}] = #{quote_value(value)}" first = false end connection.update( "UPDATE #{self.class.table_name} " + "SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} " + "WHERE #{where}", "#{self.class.name} Update") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hiroeorz-custom-active-record-0.1.1 | lib/custom-active-record/plurals-pkeys-base.rb |
hiroeorz-custom-active-record-0.1.2 | lib/custom_active_record/plurals_pkeys_base.rb |