Home > Blockchain >  Order number of installments based on expected_date
Order number of installments based on expected_date

Time:12-02

I have an installment of payment and this table(installment) have columns called number and expected_date

@payment.installments.each { |installment| installment.update(number:xxx) }
i tried something like this

for example: payment has 6 installments, i need to order each installment.number and update the number based on his expected date? DESC ORDER Some tip?

CodePudding user response:

I would do this:

@payment.installments
  .order(:expected_date)
  .each_with_index { |installment, index| installment.update_column(:number, index) }
  • Related