From 31769d59efa4e22f007ce0137cd37a0d409fe5f0 Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Mon, 8 Aug 2022 11:39:17 +0200 Subject: [PATCH] fix: Fix task to assign subscription to events (#368) --- lib/tasks/events.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/events.rake b/lib/tasks/events.rake index d715776b551..0ede0b3fea4 100644 --- a/lib/tasks/events.rake +++ b/lib/tasks/events.rake @@ -12,7 +12,9 @@ namespace :events do desc 'Fill missing subscription_id' task fill_subscription: :environment do Event.where(subscription_id: nil).find_each do |event| - event.update!(subscription_id: event.customer.active_subscription&.id) + subscription = event.customer.active_subscription || event.customer.subscriptions.order(&:created_at).last + + event.update!(subscription_id: subscription.id) end end end