ruby on rails - ActiveRecord: update_all shows query in debug log, but doesn't execute in DB? -
i've got following update query running in function called before_destroy
callback in rails model:
annotation.joins(:annotation_groups) .where({'annotation_groups.group_id' => self.id}) .update_all({qc_approved: false}) if doc.in_qc?`
(i've tried following simpler version see if angle works: self.annotations.update_all({qc_approved: false})
)
both generate below sql query in "server development log" (debugging in rubymine):
update "annotations" set "qc_approved" = 'f' "annotations"."id" in (select "annotations"."id" "annotations" inner join "annotation_groups" on "annotation_groups"."annotation_id" = "annotations"."id" "annotation_groups"."group_id" = 159)
however, far can tell, sql never causes db update, though destroy process afterwards works fine. can set breakpoint directly after statement , @ database, , qc_approved
fields still true. however, can copy , paste statement postgres console , run it, , updates fields correctly.
is aware cause behavior? before_destroy
exist in own strange alternate transactional universe causes odd behavior this? scenario cause sql show in server log not make db?
thanks quick , helpful comments above confirming nature of callback inside larger transaction, figured out.. despite name, before_destroy
executing after dependent destroy calls, joined annotation_group
table row destroyed before update
statement relied on called in transaction.
to more specific, added :prepend => true
before_destroy
definition ran before destroys intended.
Comments
Post a Comment