When opening the rails console I proceed with the following query
notUpDate = Package.where(["state = :elEstado and viality_to < :laFecha", {elEstado: 'published', laFecha: '2022-12-31'}])
Then I update the date:
notUpDate.update_all(viality_to: "2022-12-31".to_date)
The problem is that : notUpDate.save does not save all the information in the database.
6] pry(main)> notUpDate.save
NoMethodError: undefined method `save' for #<Package::ActiveRecord_Relation:0x00000019533e78>
from /<Proyecto>/shared/bundle/ruby/2.1.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:136:in `method_missing'
notUpDate.save_all doesn't work for me either:
[11] pry(main)> notUpDate.save_all
NoMethodError: undefined method `save_all' for #<Package::ActiveRecord_Relation:0x00000019533e78>
from <ElProyecto>/shared/bundle/ruby/2.1.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:136:in `method_missing'
But how do I update all the values at once?
I'm thinking something like
for i en query
i.update_column :viality_to, "2021-31-21".to_date
i.save
Can someone explain to me?
Note: Where collections do not need .save or .save_all
The mere fact of doing update_all() implicitly brings a save