I am trying add an additional check on the issues that only those issues are selected for which there is no transaction record after the last reminder. Please help me how can I do that.
Office.all.each do |office|
transaction_ids = []
office.issues.where("issues.account > 1").each do |issue|
transaction = issue.transactions.where(type: :paid).order(:date).last
transaction_ids << transaction.id if transaction.date < Reminder.last.date
end
Worker.perform_async(transaction_ids) if transaction_ids.any?
end
Update
I was thinking of something like this but it doesn't work because I am getting this error PG::UndefinedTable: ERROR: missing FROM-clause entry for table "last"
office.issues.where("issues.account > 1").joins(:transactions).where(transactions.last.date < Reminder.last.date).each do |issue|