basecrm-ruby
basecrm-ruby copied to clipboard
Sort deals by date of last note?
My biz team updates Deals with Notes quite frequently, but unfortunately it appears a note does not update the deal's updated_at
value (e.g. a deal might be last updated May 24 even though someone added a note yesterday).
I tried sorting my array of deals based on the presence of a note, however this query is so unbelievably slow that the page times out every time:
session.deals.all(stage: :incoming).sort_by do |deal|
(deal.notes.all.present? && deal.notes.all.last[:updated_at]) ||
deal[:updated_at]
end
Any advice much appreciated!
You can try session.deals.all(stage: incoming, sort_by: :last_activity, sort_order: :desc)
. It won't exactly sort by the date of last note, because other things also count as activity (adding tasks, updating, etc.) but might be enough for your purpose.
You want to sort by last_activity_at
e.g. client.deals.all(sort_by: :last_activity_at)
unfortunetly it's not exposed by the api, even the attribute is. I'll prioritise it for the next milestone.