Problem
When a conversation record is created/updated, we need to update the open_conversations_count and closed _conversations_count counter cache columns on the projects table.
We'll need to update the counts based on the following logic:
- on
insert
inc: [open_conversations_count: 1]
- on
update
status "open" => "closed"
inc: [closed_conversations_count: 1, open_conversations_count: -1]
- on
update
status "closed" => "open"
inc: [closed_conversations_count: -1, open_conversations_count: 1]
We'll add prepare_changes to increment one and decrement the other. See this example in Ecto
A useful post on this, as well: https://medium.com/@kaisersly/prepare-changes-and-counter-cache-abd93b8a20a
Problem
When a
conversationrecord is created/updated, we need to update theopen_conversations_countandclosed _conversations_countcounter cache columns on theprojectstable.project_idtoConversationWe'll need to update the counts based on the following logic:
insertinc: [open_conversations_count: 1]updatestatus"open" => "closed"inc: [closed_conversations_count: 1, open_conversations_count: -1]updatestatus"closed" => "open"inc: [closed_conversations_count: -1, open_conversations_count: 1]We'll add
prepare_changesto increment one and decrement the other. See this example in EctoA useful post on this, as well: https://medium.com/@kaisersly/prepare-changes-and-counter-cache-abd93b8a20a