Module: ActiveRecord::Associations::HyperHasManyAssociationExtension
- Included in:
- HasManyAssociation
- Defined in:
- lib/associations/hyper_has_many_association_extension.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete_records_with_hypertable(records) ⇒ Object
- #find_with_hypertable(*args) ⇒ Object
- #insert_record_with_hypertable(record) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/associations/hyper_has_many_association_extension.rb', line 4 def self.included(base) base.class_eval do alias_method :find_without_hypertable, :find alias_method :find, :find_with_hypertable alias_method :delete_records_without_hypertable, :delete_records alias_method :delete_records, :delete_records_with_hypertable alias_method :insert_record_without_hypertable, :insert_record alias_method :insert_record, :insert_record_with_hypertable alias_method :create_record_without_hypertable, :create_record alias_method :create_record, :create_record_with_hypertable end end |
Instance Method Details
#delete_records_with_hypertable(records) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/associations/hyper_has_many_association_extension.rb', line 47 def delete_records_with_hypertable(records) if @reflection.klass <= ActiveRecord::HyperBase cells_to_delete = [] records.each {|r| # remove association cells from in memory object r.send("#{@reflection.primary_key_name}=", nil) r.save # make list of cells that need to be removed from hypertable cells_to_delete << @owner.connection.cell_native_array( @owner.ROW, @reflection.association_foreign_key, r.ROW ) } @owner.delete_cells(cells_to_delete, @owner.class.table_name) else delete_records_without_hypertable(records) end end |
#find_with_hypertable(*args) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/associations/hyper_has_many_association_extension.rb', line 20 def find_with_hypertable(*args) if @reflection.klass <= ActiveRecord::HyperBase associated_object_ids = @owner.send(@reflection.association_foreign_key).keys @reflection.klass.find(associated_object_ids) else find_without_hypertable(*args) end end |
#insert_record_with_hypertable(record) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/associations/hyper_has_many_association_extension.rb', line 29 def insert_record_with_hypertable(record) if @reflection.klass <= ActiveRecord::HyperBase raise "missing ROW key on record" if record.ROW.blank? @owner.send(@reflection.association_foreign_key)[record.ROW] = 1 @owner.write_cells([@owner.connection.cell_native_array( @owner.ROW, @reflection.association_foreign_key, record.ROW, "1" )]) record.send("#{@reflection.primary_key_name}=", @owner.ROW) record.save self.reset else insert_record_without_hypertable(record) end end |