Module: Partitioned::ActiveRecordOverrides
- Included in:
- PartitionedBase
- Defined in:
- lib/partitioned/active_record_overrides.rb
Overview
methods that need to be override in an ActiveRecord::Base derived class so that we can support partitioning
Instance Method Summary collapse
-
#arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys) ⇒ Hash
arel_attribute_values needs to return attributes (and their values) associated with the dynamic_arel_table instead of the static arel_table provided by ActiveRecord.
-
#delete ⇒ optional
Delete just needs a wrapper around it to specify the specific partition.
Instance Method Details
#arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys) ⇒ Hash
arel_attribute_values needs to return attributes (and their values) associated with the dynamic_arel_table instead of the static arel_table provided by ActiveRecord.
The standard release of this function gathers a collection of attributes and creates a wrapper function around them that names the table they are associated with. that naming is incorrect for partitioned tables.
We call the standard releases method then retrofit our partitioned table into the hash that is returned.
24 25 26 27 28 |
# File 'lib/partitioned/active_record_overrides.rb', line 24 def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys) attrs = super actual_arel_table = dynamic_arel_table() return Hash[*attrs.map{|k,v| [actual_arel_table[k.name], v]}.flatten] end |
#delete ⇒ optional
Delete just needs a wrapper around it to specify the specific partition.
34 35 36 37 38 39 40 |
# File 'lib/partitioned/active_record_overrides.rb', line 34 def delete if persisted? self.class.from_partition(*self.class.partition_key_values(attributes)).delete(id) end @destroyed = true freeze end |