basecrm-ruby icon indicating copy to clipboard operation
basecrm-ruby copied to clipboard

Sort deals by date of last note?

Open chhhris opened this issue 10 years ago • 2 comments

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!

chhhris avatar Jul 31 '14 17:07 chhhris

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.

obrok avatar Aug 01 '14 10:08 obrok

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.

iaintshine avatar Sep 24 '15 20:09 iaintshine