Module: CompositePrimaryKeys::ActiveRecord::Persistence
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/composite_primary_keys/persistence.rb
Instance Method Summary collapse
Instance Method Details
#relation_for_destroy ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/composite_primary_keys/persistence.rb', line 4 def relation_for_destroy # CPK #pk = self.class.primary_key #column = self.class.columns_hash[pk] #substitute = self.class.connection.substitute_at(column, 0) #relation = self.class.unscoped.where( # self.class.arel_table[pk].eq(substitute)) #relation.bind_values = [[column, id]] relation = self.class.unscoped Array(self.class.primary_key).each_with_index do |key, index| column = self.class.columns_hash[key] substitute = self.class.connection.substitute_at(column, index) relation = relation.where(self.class.arel_table[key].eq(substitute)) relation.bind_values += [[column, self[key]]] end relation end |
#touch(name = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/composite_primary_keys/persistence.rb', line 25 def touch(name = nil) raise ActiveRecordError, "cannot touch on a new record object" unless persisted? attributes = attributes << name if name unless attributes.empty? current_time = current_time_from_proper_timezone changes = {} attributes.each do |column| column = column.to_s changes[column] = write_attribute(column, current_time) end changes[self.class.locking_column] = increment_lock if locking_enabled? changed_attributes.except!(*changes.keys) relation = self.class.send(:relation) arel_table = self.class.arel_table primary_key = self.class.primary_key # CPK #self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1 primary_key_predicate = relation.cpk_id_predicate(arel_table, Array(primary_key), Array(id)) self.class.unscoped.where(primary_key_predicate).update_all(changes) == 1 else true end end |