Module: Errgonomic::Rails::ActiveRecordBulkWrite

Defined in:
lib/errgonomic/rails/active_record_optional.rb

Overview

A bulk write never passes an attribute writer: it casts and serializes each value it was handed straight into the statement. Unwrapping the row on the way in is what lets a Some cross that boundary whatever the column type is. insert, insert! and upsert route through their plural forms, so they are covered here too. A nested structure inside a value is the caller's own and is left as it is.

Instance Method Summary collapse

Instance Method Details

#insert_all(attributes, **kwargs) ⇒ Object



731
732
733
# File 'lib/errgonomic/rails/active_record_optional.rb', line 731

def insert_all(attributes, **kwargs)
  super(Errgonomic::Rails.unwrap_option_rows(attributes), **kwargs)
end

#insert_all!(attributes, **kwargs) ⇒ Object



735
736
737
# File 'lib/errgonomic/rails/active_record_optional.rb', line 735

def insert_all!(attributes, **kwargs)
  super(Errgonomic::Rails.unwrap_option_rows(attributes), **kwargs)
end

#update_all(updates) ⇒ Object

Examples:

Note.insert_all([{ title: Some('Wanderer'), rank: None() }])
Note.where(title: 'Wanderer').update_all(rank: Some(3))
Note.find_by(title: 'Wanderer').rank # => Some(3)


727
728
729
# File 'lib/errgonomic/rails/active_record_optional.rb', line 727

def update_all(updates)
  super(updates.is_a?(Hash) ? Errgonomic::Rails.unwrap_option_values(updates) : updates)
end

#upsert_all(attributes, **kwargs) ⇒ Object



739
740
741
# File 'lib/errgonomic/rails/active_record_optional.rb', line 739

def upsert_all(attributes, **kwargs)
  super(Errgonomic::Rails.unwrap_option_rows(attributes), **kwargs)
end