re: Why is Rails ActiveRelation.update_all updating a different set of records? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: What is the SQL generated by related_comments.count. Count will change the query sometimes if Rails decides it doesn't need the join/includes. I'...
 

Here's the SQL for related_comments.count:

(22.0ms)  SELECT COUNT(*) FROM ( (SELECT "comments".* FROM "comments"
WHERE (("comments"."ancestry" LIKE '12/%' OR "comments"."ancestry" = '12')
OR "comments"."id" = 12)) UNION (SELECT "comments".* FROM "comments" WHERE
1=0 ORDER BY COALESCE("comments"."ancestry", '') ASC) ) "comments" WHERE
"comments"."user_id" = $1  [["user_id", 11]] [sql_query]

And for the select:

(4.1ms)  SELECT "comments".* FROM ( (SELECT "comments".* FROM "comments"
WHERE (("comments"."ancestry" LIKE '12/%' OR "comments"."ancestry" = '12')
OR "comments"."id" = 12)) UNION (SELECT "comments".* FROM "comments" WHERE
1=0 ORDER BY COALESCE("comments"."ancestry", '') ASC) ) "comments" WHERE
"comments"."user_id" = $1  [["user_id", 11]] [sql_query]

FWIW the code I'm using does not run related_comments.count; that was to demonstrate how many records should be updated.

code of conduct - report abuse