Skip to content

Instantly share code, notes, and snippets.

@cjavdev
Created September 21, 2023 17:11
Show Gist options
  • Save cjavdev/7877e92cb2aed3a2b6c26675893204f3 to your computer and use it in GitHub Desktop.
Save cjavdev/7877e92cb2aed3a2b6c26675893204f3 to your computer and use it in GitHub Desktop.
ActiveRecord::Base.connection.execute(<<-SQL)
UPDATE projects
SET comments_count = (
SELECT COUNT(*)
FROM comments
WHERE comments.commentable_id = projects.id
AND comments.commentable_type = 'Project'
)
SQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment